2024-02-09 01:23:38 +01:00
|
|
|
using Avalonia;
|
2024-02-08 00:54:45 +01:00
|
|
|
using Avalonia.ReactiveUI;
|
|
|
|
|
using Avalonia.Threading;
|
|
|
|
|
|
|
|
|
|
using InkForge.Common;
|
2024-02-09 01:23:38 +01:00
|
|
|
using InkForge.Data;
|
2024-02-08 00:54:45 +01:00
|
|
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
using ReactiveUI;
|
|
|
|
|
|
|
|
|
|
using Splat;
|
|
|
|
|
using Splat.Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
static class Program
|
|
|
|
|
{
|
|
|
|
|
[STAThread]
|
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
=> BuildAvaloniaApp()
|
2024-02-08 01:22:32 +01:00
|
|
|
.UseMicrosoftDependencyInjection()
|
2024-02-08 00:54:45 +01:00
|
|
|
.StartWithClassicDesktopLifetime(args);
|
|
|
|
|
|
|
|
|
|
public static AppBuilder BuildAvaloniaApp()
|
|
|
|
|
=> AppBuilder.Configure<App>()
|
|
|
|
|
.UsePlatformDetect()
|
|
|
|
|
.UseReactiveUI()
|
2024-02-09 01:23:38 +01:00
|
|
|
.WithInterFont()
|
2024-02-08 00:54:45 +01:00
|
|
|
.LogToTrace();
|
|
|
|
|
|
|
|
|
|
private static void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.UseMicrosoftDependencyResolver();
|
|
|
|
|
var mutableResolver = Locator.CurrentMutable;
|
|
|
|
|
mutableResolver.InitializeSplat();
|
|
|
|
|
mutableResolver.InitializeReactiveUI();
|
|
|
|
|
|
2024-02-09 01:23:38 +01:00
|
|
|
services.AddInkForge();
|
2024-02-08 00:54:45 +01:00
|
|
|
}
|
|
|
|
|
|
2024-02-08 01:19:26 +01:00
|
|
|
private static void OnSetup(this IServiceCollection services, AppBuilder appBuilder)
|
2024-02-08 00:54:45 +01:00
|
|
|
{
|
|
|
|
|
var dispatcher = Dispatcher.UIThread;
|
|
|
|
|
|
|
|
|
|
var app = appBuilder.Instance!;
|
2024-02-08 01:19:26 +01:00
|
|
|
services
|
2024-02-08 00:54:45 +01:00
|
|
|
.AddSingleton(app)
|
|
|
|
|
.AddSingleton(app.ApplicationLifetime!)
|
|
|
|
|
.AddSingleton(app.PlatformSettings!)
|
|
|
|
|
.AddSingleton(dispatcher);
|
|
|
|
|
|
2024-02-08 01:19:26 +01:00
|
|
|
var serviceProvider = services.BuildServiceProvider();
|
|
|
|
|
serviceProvider.UseMicrosoftDependencyResolver();
|
|
|
|
|
app.SetValue(App.ServiceProviderProperty, serviceProvider);
|
|
|
|
|
dispatcher.ShutdownFinished += (_, _) => serviceProvider.Dispose();
|
2024-02-08 00:54:45 +01:00
|
|
|
}
|
|
|
|
|
|
2024-02-08 01:22:32 +01:00
|
|
|
private static AppBuilder UseMicrosoftDependencyInjection(this AppBuilder builder)
|
2024-02-08 00:54:45 +01:00
|
|
|
{
|
2024-02-08 01:19:26 +01:00
|
|
|
ServiceCollection services = [];
|
|
|
|
|
ConfigureServices(services);
|
|
|
|
|
builder.AfterSetup(services.OnSetup);
|
2024-02-08 00:54:45 +01:00
|
|
|
return builder;
|
|
|
|
|
}
|
|
|
|
|
}
|