-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.axaml.cs
More file actions
55 lines (48 loc) · 2.28 KB
/
Copy pathApp.axaml.cs
File metadata and controls
55 lines (48 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Panzerfaust.ViewModels;
using Panzerfaust.Views;
using Microsoft.Extensions.DependencyInjection;
namespace Panzerfaust
{
public partial class App : Application
{
public IServiceProvider? ServiceProvider { get; private set; }
public new static App? Current => Application.Current as App;
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
Models.AppPaths.EnsureDirectories();
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
var window = new MainWindow();
var services = new ServiceCollection();
services.AddSingleton<Service.IProjectService, Service.ProjectService>();
services.AddSingleton<Service.IGitHubReleaseService, Service.GitHubReleaseService>();
services.AddSingleton<Service.IPolyHavenService, Service.PolyHavenService>();
services.AddSingleton<Service.IStorageProviderService>(_ => new Service.StorageProviderService(window));
services.AddSingleton<Service.IEngineService, Service.EngineService>();
services.AddTransient<ProjectWindowViewModel>();
services.AddTransient<Func<ProjectWindowViewModel>>(sp => () =>
{
var mainVm = sp.GetRequiredService<MainWindowViewModel>();
return new ProjectWindowViewModel(
sp.GetRequiredService<Service.IStorageProviderService>(),
sp.GetRequiredService<Service.IProjectService>(),
sp.GetRequiredService<Service.IEngineService>(),
mainVm.DefaultProjectLocation);
});
services.AddTransient<MainWindowViewModel>();
ServiceProvider = services.BuildServiceProvider();
window.DataContext = ServiceProvider.GetRequiredService<MainWindowViewModel>();
desktop.MainWindow = window;
window.Show();
}
base.OnFrameworkInitializationCompleted();
}
}
}