forked from block-core/angor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceCollectionExtensions.cs
More file actions
94 lines (87 loc) · 3.97 KB
/
ServiceCollectionExtensions.cs
File metadata and controls
94 lines (87 loc) · 3.97 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using Angor.UI.Model;
using Angor.UI.Model.Implementation;
using Angor.UI.Model.Implementation.Projects;
using AngorApp.Core;
using AngorApp.Design;
using AngorApp.Sections;
using AngorApp.Sections.Browse;
using AngorApp.Sections.Founder;
using AngorApp.Sections.Home;
using AngorApp.Sections.Portfolio;
using AngorApp.Sections.Shell;
using AngorApp.Sections.Wallet;
using AngorApp.UI.Services;
using Avalonia.Controls.Notifications;
using Microsoft.Extensions.DependencyInjection;
using Zafiro.Avalonia.Controls.Navigation;
using Zafiro.Avalonia.Dialogs;
using Zafiro.Avalonia.Services;
using Zafiro.UI;
namespace AngorApp.Composition;
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddUIServices(this IServiceCollection services, Control parent)
{
var topLevel = TopLevel.GetTopLevel(parent);
return services
.AddSingleton<ILauncherService>(_ => new LauncherService(topLevel!.Launcher))
.AddSingleton<IDialog, DesktopDialog>()
.AddSingleton<IActiveWallet, ActiveWallet>()
.AddSingleton<INotificationService>(_ => new NotificationService(
new WindowNotificationManager(topLevel)
{
Position = NotificationPosition.BottomRight
}
))
.AddSingleton<UIServices>(sp => new UIServices(
sp.GetRequiredService<ILauncherService>(),
sp.GetRequiredService<IDialog>(),
sp.GetRequiredService<INotificationService>(),
sp.GetRequiredService<IActiveWallet>()
));
}
public static IServiceCollection AddUIModelServices(this IServiceCollection services)
{
return services
.AddSingleton<IWalletProvider, WalletProviderDesign>()
.AddSingleton<IWalletBuilder, WalletBuilderDesign>()
.AddSingleton<IWalletFactory, WalletFactory>()
.AddSingleton<IProjectService>(sp =>
{
var loggerFactory = LoggerConfig.CreateFactory();
return new ProjectService(
DependencyFactory.GetIndexerService(loggerFactory),
DependencyFactory.GetRelayService(loggerFactory)
);
});
}
private delegate IBrowseSectionViewModel BrowseSectionViewModelFactory(INavigator navigator);
public static IServiceCollection AddViewModels(this IServiceCollection services)
{
return services
.AddTransient<BrowseSectionViewModelFactory>(sp =>
navigator => ActivatorUtilities.CreateInstance<BrowseSectionViewModel>(sp, navigator))
.AddTransient<NavigationViewModel>(sp =>
new NavigationViewModel(navigator =>
sp.GetRequiredService<BrowseSectionViewModelFactory>()(navigator)
))
.AddSingleton<ISectionsFactory, SectionsFactory>()
.AddSingleton<Lazy<IMainViewModel>>(sp => new Lazy<IMainViewModel>(sp.GetRequiredService<IMainViewModel>))
.AddTransient<IHomeSectionViewModel>(sp =>
new HomeSectionViewModel(
sp.GetRequiredService<IActiveWallet>(),
sp.GetRequiredService<UIServices>(),
() => sp.GetRequiredService<Lazy<IMainViewModel>>().Value
))
.AddTransient<IWalletSectionViewModel, WalletSectionViewModel>()
// // This registration could be maintained for alternative uses, but for navigation we will use the delegate
.AddTransient<IBrowseSectionViewModel, BrowseSectionViewModel>()
.AddTransient<IPortfolioSectionViewModel, PortfolioSectionViewModel>()
.AddTransient<IFounderSectionViewModel, FounderSectionViewModel>()
.AddSingleton<IMainViewModel>(sp =>
new MainViewModel(
sp.GetRequiredService<ISectionsFactory>().CreateSections(),
sp.GetRequiredService<UIServices>()
));
}
}