From cf6f87bea88df3f90e33dfdc5bb16f47b8716054 Mon Sep 17 00:00:00 2001 From: "Emma@Rory&" Date: Mon, 24 Jul 2023 20:57:23 +0200 Subject: Start of MRU Desktop --- MatrixRoomUtils.Desktop/App.axaml.cs | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 MatrixRoomUtils.Desktop/App.axaml.cs (limited to 'MatrixRoomUtils.Desktop/App.axaml.cs') diff --git a/MatrixRoomUtils.Desktop/App.axaml.cs b/MatrixRoomUtils.Desktop/App.axaml.cs new file mode 100644 index 0000000..3dfcdee --- /dev/null +++ b/MatrixRoomUtils.Desktop/App.axaml.cs @@ -0,0 +1,43 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; +using MatrixRoomUtils.Core.Services; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace MatrixRoomUtils.Desktop; + +public partial class App : Application { + public IHost host { get; set; } + + public override void Initialize() { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() { + host = Host.CreateDefaultBuilder().ConfigureServices((ctx, services) => { + services.AddScoped(); + services.AddScoped(x => + new( + cacheStorageProvider: new FileStorageProvider(x.GetService().CacheStoragePath), + dataStorageProvider: new FileStorageProvider(x.GetService().CacheStoragePath) + ) + ); + services.AddRoryLibMatrixServices(); + // foreach (var commandClass in new ClassCollector().ResolveFromAllAccessibleAssemblies()) { + // Console.WriteLine($"Adding command {commandClass.Name}"); + // services.AddScoped(typeof(ICommand), commandClass); + // } + services.AddScoped(); + services.AddScoped(); + services.AddSingleton(this); + }).UseConsoleLifetime().Build(); + + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { + var scopeFac = host.Services.GetService(); + var scope = scopeFac.CreateScope(); + desktop.MainWindow = scope.ServiceProvider.GetRequiredService(); + } + base.OnFrameworkInitializationCompleted(); + } +} -- cgit 1.5.1