using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; using MatrixRoomUtils.Core.Services; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Sentry; 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.AddSingleton(); services.AddSingleton(); services.AddSingleton(x => new( cacheStorageProvider: new FileStorageProvider(x.GetService().CacheStoragePath), dataStorageProvider: new FileStorageProvider(x.GetService().DataStoragePath) ) ); services.AddSingleton(new RoryLibMatrixConfiguration() { AppName = "MatrixRoomUtils.Desktop" }); services.AddRoryLibMatrixServices(); // foreach (var commandClass in new ClassCollector().ResolveFromAllAccessibleAssemblies()) { // Console.WriteLine($"Adding command {commandClass.Name}"); // services.AddScoped(typeof(ICommand), commandClass); // } services.AddSingleton(); services.AddSingleton(); 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(); } }