71 lines
2.7 KiB
C#
71 lines
2.7 KiB
C#
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<IScreen>(() => new MainScreenViewModel());
|
|
mutable.RegisterLazySingleton(() => RestService.For<IGamenight>("http://localhost:8080"));
|
|
|
|
mutable.Register(() => new AddGamenightViewModel(
|
|
locator.GetRequiredService<IGamenight>(),
|
|
locator.GetRequiredService<GamenightModel>()));
|
|
mutable.Register(() => new LoginViewModel(
|
|
locator.GetRequiredService<IScreen>(),
|
|
locator.GetRequiredService<IGamenight>(),
|
|
locator.GetRequiredService<GamenightModel>()));
|
|
mutable.Register(() => new GamenightsViewModel(
|
|
locator.GetRequiredService<IScreen>(),
|
|
locator.GetRequiredService<IGamenight>(),
|
|
locator.GetRequiredService<GamenightModel>(),
|
|
locator.GetRequiredService<LoginViewModel>()));
|
|
mutable.Register(() => new MainViewModel(
|
|
locator.GetRequiredService<IScreen>(),
|
|
locator.GetRequiredService<GamenightModel>(),
|
|
locator.GetRequiredService<IGamenight>(),
|
|
locator.GetRequiredService<LoginViewModel>(),
|
|
locator.GetRequiredService<GamenightsViewModel>()));
|
|
|
|
|
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
|
{
|
|
desktop.MainWindow = new MainWindow
|
|
{
|
|
DataContext = Locator.Current.GetService<MainViewModel>()
|
|
};
|
|
}
|
|
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
|
|
{
|
|
singleViewPlatform.MainView = new MainView
|
|
{
|
|
DataContext = Locator.Current.GetService<MainViewModel>()
|
|
};
|
|
}
|
|
|
|
Locator.Current.GetService<IScreen>()?.Router.Navigate.Execute(Locator.Current.GetService<GamenightsViewModel>() ?? throw new InvalidOperationException("Could not find initial viewmodel to navigate to"));
|
|
|
|
base.OnFrameworkInitializationCompleted();
|
|
}
|
|
} |