using System; using System.Reactive.Concurrency; using System.Reactive.Disposables; using System.Windows; using System.Windows.Threading; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using ReactiveUI; using Wabbajack.DTOs; using Wabbajack.LoginManagers; using Wabbajack.Models; using Wabbajack.Services.OSIntegrated; using Wabbajack.UserIntervention; using Wabbajack.Util; namespace Wabbajack { /// /// Interaction logic for App.xaml /// public partial class App { private readonly IServiceProvider _serviceProvider; private readonly IHost _host; public App() { _host = Host.CreateDefaultBuilder(Array.Empty()) .ConfigureLogging(c => { c.ClearProviders(); }) .ConfigureServices((host, services) => { ConfigureServices(services); }) .Build(); _serviceProvider = _host.Services; } private static IServiceCollection ConfigureServices(IServiceCollection services) { RxApp.MainThreadScheduler = new DispatcherScheduler(Dispatcher.CurrentDispatcher); services.AddOSIntegrated(); services.AddSingleton(); services.AddTransient(); services.AddTransient(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddAllSingleton(); services.AddSingleton(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); // Login Handlers services.AddTransient(); services.AddTransient(); services.AddTransient(); // Login Managers services.AddAllSingleton(); services.AddAllSingleton(); services.AddAllSingleton(); return services; } private void OnStartup(object sender, StartupEventArgs e) { RxApp.MainThreadScheduler.Schedule(0, (_, _) => { var mainWindow = _serviceProvider.GetRequiredService(); mainWindow!.Show(); return Disposable.Empty; }); } private void OnExit(object sender, ExitEventArgs e) { using (_host) { _host.StopAsync(); } base.OnExit(e); } } }