using System; using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; using FrontendAvalonia.Extensions; using FrontendAvalonia.Models; using FrontendAvalonia.Services.GamenightApi; using FrontendAvalonia.ViewModels; using FrontendAvalonia.Views; using ReactiveUI; using Refit; using Splat; namespace FrontendAvalonia; public partial class App : Application { public override void Initialize() { AvaloniaXamlLoader.Load(this); } public override void OnFrameworkInitializationCompleted() { var mutable = Locator.CurrentMutable; var locator = Locator.Current ?? throw new InvalidOperationException("Locator should not be null here."); mutable.RegisterLazySingleton(() => new GamenightModel()); mutable.RegisterLazySingleton(() => new MainScreenViewModel()); mutable.RegisterLazySingleton(() => RestService.For("http://localhost:8080")); mutable.Register(() => new AddGamenightViewModel( locator.GetRequiredService(), locator.GetRequiredService())); mutable.Register(() => new LoginViewModel( locator.GetRequiredService(), locator.GetRequiredService(), locator.GetRequiredService())); mutable.Register(() => new GamenightsViewModel( locator.GetRequiredService(), locator.GetRequiredService(), locator.GetRequiredService(), locator.GetRequiredService())); mutable.Register(() => new MainViewModel( locator.GetRequiredService(), locator.GetRequiredService(), locator.GetRequiredService(), locator.GetRequiredService(), locator.GetRequiredService())); if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { desktop.MainWindow = new MainWindow { DataContext = Locator.Current.GetService() }; } else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) { singleViewPlatform.MainView = new MainView { DataContext = Locator.Current.GetService() }; } Locator.Current.GetService()?.Router.Navigate.Execute(Locator.Current.GetService() ?? throw new InvalidOperationException("Could not find initial viewmodel to navigate to")); base.OnFrameworkInitializationCompleted(); } }