Added the abilty to load configuration sections using * pattern
This commit is contained in:
@@ -18,13 +18,15 @@ public partial class App : Application
|
|||||||
public override async void OnFrameworkInitializationCompleted()
|
public override async void OnFrameworkInitializationCompleted()
|
||||||
{
|
{
|
||||||
IHost? host = DefaultBuilder.Create()
|
IHost? host = DefaultBuilder.Create()
|
||||||
|
.AddConfiguration<VaultConfiguration>(args => args.Name = "Personal",
|
||||||
|
"Vault:*")
|
||||||
.ConfigureServices((context, services) =>
|
.ConfigureServices((context, services) =>
|
||||||
{
|
{
|
||||||
services.AddAvalonia();
|
services.AddAvalonia();
|
||||||
services.AddHandler<AppHandler>();
|
services.AddHandler<AppHandler>();
|
||||||
|
|
||||||
services.AddTransient<IVaultComponent, VaultComponent>();
|
services.AddTransient<IVaultComponent, VaultComponent>();
|
||||||
services.AddInitializer<VaultComponentsInitializer>();
|
services.AddInitializer<VaultConfigurationInitializer>();
|
||||||
|
|
||||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime)
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime)
|
||||||
{
|
{
|
||||||
@@ -32,11 +34,19 @@ public partial class App : Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
services.AddSingleton<IVaultHostCollection, VaultHostCollection>();
|
services.AddSingleton<IVaultHostCollection, VaultHostCollection>();
|
||||||
|
services.AddSingleton<IVaultFactory, VaultFactory>();
|
||||||
|
services.AddHandler<VaultHandler>();
|
||||||
|
|
||||||
services.AddTemplate<MainViewModel, MainView>("Main");
|
services.AddTemplate<MainViewModel, MainView>("Main");
|
||||||
services.AddHandler<MainViewModelHandler>();
|
services.AddHandler<MainViewModelHandler>();
|
||||||
|
|
||||||
services.AddConfiguration<VaultConfiguration>(args => args.Name = "Personal", "Vault:Personal");
|
services.AddTransient<FooterViewModel>();
|
||||||
|
|
||||||
|
services.AddTemplate<ManageNavigationViewModel, ManageNavigationView>();
|
||||||
|
services.AddTemplate<ManageViewModel, ManageView>("Manage");
|
||||||
|
|
||||||
|
services.AddTemplate<CreateVaultNavigationViewModel, CreateVaultNavigationView>();
|
||||||
|
services.AddTemplate<CreateVaultViewModel, CreateVaultView>("CreateVault");
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|||||||
@@ -27,4 +27,9 @@
|
|||||||
<ProjectReference Include="..\Toolkit\Toolkit.UI.Avalonia\Toolkit.UI.Avalonia.csproj" />
|
<ProjectReference Include="..\Toolkit\Toolkit.UI.Avalonia\Toolkit.UI.Avalonia.csproj" />
|
||||||
<ProjectReference Include="..\Toolkit\Toolkit.UI.Controls.Avalonia\Toolkit.UI.Controls.Avalonia.csproj" />
|
<ProjectReference Include="..\Toolkit\Toolkit.UI.Controls.Avalonia\Toolkit.UI.Controls.Avalonia.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="ManageNavigationView.axaml.cs">
|
||||||
|
<DependentUpon>ManageNavigationView.axaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<SettingsExpander
|
||||||
|
x:Class="Bitvault.Avalonia.CreateVaultNavigationView"
|
||||||
|
xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
Description="Keep organized by separating your things into vaults."
|
||||||
|
Header="Create a new vault">
|
||||||
|
<SettingsExpander.Footer>
|
||||||
|
<Button MinWidth="132" Content="Create vault">
|
||||||
|
<Interaction.Behaviors>
|
||||||
|
<EventTriggerBehavior EventName="Click">
|
||||||
|
<NavigateAction Route="CreateVault" />
|
||||||
|
</EventTriggerBehavior>
|
||||||
|
</Interaction.Behaviors>
|
||||||
|
</Button>
|
||||||
|
</SettingsExpander.Footer>
|
||||||
|
</SettingsExpander>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using Toolkit.UI.Controls.Avalonia;
|
||||||
|
|
||||||
|
namespace Bitvault.Avalonia;
|
||||||
|
|
||||||
|
public partial class CreateVaultNavigationView : SettingsExpander
|
||||||
|
{
|
||||||
|
public CreateVaultNavigationView() => InitializeComponent();
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<ContentDialog
|
||||||
|
x:Class="Bitvault.Avalonia.CreateVaultView"
|
||||||
|
xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:Bitvault"
|
||||||
|
Title="Create vault"
|
||||||
|
x:DataType="vm:CreateVaultViewModel"
|
||||||
|
CloseButtonText="Cancel"
|
||||||
|
PrimaryButtonText="Create">
|
||||||
|
<StackPanel Width="400">
|
||||||
|
<TextBox
|
||||||
|
Margin="0,0,0,18"
|
||||||
|
Text="{Binding Name}"
|
||||||
|
Watermark="Enter vault name" />
|
||||||
|
<TextBox Margin="0,0,0,18" Watermark="Enter password" />
|
||||||
|
<TextBox Watermark="Confirm password" />
|
||||||
|
</StackPanel>
|
||||||
|
</ContentDialog>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using Toolkit.UI.Controls.Avalonia;
|
||||||
|
|
||||||
|
namespace Bitvault.Avalonia;
|
||||||
|
|
||||||
|
public partial class CreateVaultView : ContentDialog
|
||||||
|
{
|
||||||
|
public CreateVaultView() => InitializeComponent();
|
||||||
|
}
|
||||||
@@ -4,7 +4,10 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:vm="using:Bitvault"
|
xmlns:vm="using:Bitvault"
|
||||||
x:DataType="vm:MainViewModel">
|
x:DataType="vm:MainViewModel">
|
||||||
<NavigationView MenuItemTemplate="{Binding Template}" MenuItemsSource="{Binding}">
|
<NavigationView
|
||||||
|
FooterMenuItemsSource="{Binding Footer}"
|
||||||
|
MenuItemTemplate="{Binding Template}"
|
||||||
|
MenuItemsSource="{Binding}">
|
||||||
<Frame x:Name="Main">
|
<Frame x:Name="Main">
|
||||||
<Interaction.Behaviors>
|
<Interaction.Behaviors>
|
||||||
<EventTriggerBehavior EventName="Loaded">
|
<EventTriggerBehavior EventName="Loaded">
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<NavigationViewItem
|
||||||
|
x:Class="Bitvault.Avalonia.ManageNavigationView"
|
||||||
|
xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
Content="Manage Vaults">
|
||||||
|
<Interaction.Behaviors>
|
||||||
|
<EventTriggerBehavior EventName="Tapped">
|
||||||
|
<NavigateAction Context="Main" Route="Manage" />
|
||||||
|
</EventTriggerBehavior>
|
||||||
|
</Interaction.Behaviors>
|
||||||
|
</NavigationViewItem>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using Toolkit.UI.Controls.Avalonia;
|
||||||
|
|
||||||
|
namespace Bitvault.Avalonia;
|
||||||
|
|
||||||
|
public partial class ManageNavigationView : NavigationViewItem
|
||||||
|
{
|
||||||
|
public ManageNavigationView() => InitializeComponent();
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<UserControl
|
||||||
|
x:Class="Bitvault.Avalonia.ManageView"
|
||||||
|
xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:Bitvault"
|
||||||
|
x:DataType="vm:ManageViewModel">
|
||||||
|
<ScrollViewer Padding="12" HorizontalAlignment="Stretch">
|
||||||
|
<ItemsControl
|
||||||
|
MaxWidth="768"
|
||||||
|
ItemTemplate="{ReflectionBinding Template}"
|
||||||
|
ItemsSource="{Binding}" />
|
||||||
|
</ScrollViewer>
|
||||||
|
</UserControl>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
|
||||||
|
namespace Bitvault.Avalonia;
|
||||||
|
|
||||||
|
public partial class ManageView : UserControl
|
||||||
|
{
|
||||||
|
public ManageView() => InitializeComponent();
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Toolkit.Foundation;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Bitvault.Avalonia;
|
namespace Bitvault.Avalonia;
|
||||||
|
|
||||||
@@ -17,6 +18,5 @@ public class VaultComponent :
|
|||||||
|
|
||||||
services.AddTemplate<VaultViewModel, VaultView>("Vault");
|
services.AddTemplate<VaultViewModel, VaultView>("Vault");
|
||||||
services.AddTemplate<LockViewModel, LockView>("Lock");
|
services.AddTemplate<LockViewModel, LockView>("Lock");
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
Content="{Binding Name}"
|
Content="{Binding Name}"
|
||||||
MenuItemsSource="{Binding}">
|
MenuItemsSource="{Binding}">
|
||||||
<Interaction.Behaviors>
|
<Interaction.Behaviors>
|
||||||
<EventTriggerBehavior EventName="Loaded">
|
<EventTriggerBehavior EventName="Tapped">
|
||||||
<NavigateAction Context="Main" Route="Lock" />
|
<NavigateAction Context="Main" Route="Lock" />
|
||||||
</EventTriggerBehavior>
|
</EventTriggerBehavior>
|
||||||
</Interaction.Behaviors>
|
</Interaction.Behaviors>
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public partial class CreateVaultNavigationViewModel :
|
||||||
|
ObservableViewModel,
|
||||||
|
IMainNavigationViewModel
|
||||||
|
{
|
||||||
|
public CreateVaultNavigationViewModel(IServiceProvider serviceProvider,
|
||||||
|
IServiceFactory serviceFactory,
|
||||||
|
IPublisher publisher,
|
||||||
|
ISubscriber subscriber,
|
||||||
|
IDisposer disposer) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public partial class CreateVaultViewModel(IServiceProvider serviceProvider,
|
||||||
|
IServiceFactory serviceFactory,
|
||||||
|
IPublisher publisher,
|
||||||
|
ISubscriber subscriber,
|
||||||
|
IDisposer disposer) :
|
||||||
|
ObservableViewModel(serviceProvider, serviceFactory, publisher, subscriber, disposer),
|
||||||
|
IPrimaryConfirmation
|
||||||
|
{
|
||||||
|
[MaybeNull]
|
||||||
|
[ObservableProperty]
|
||||||
|
private string name;
|
||||||
|
|
||||||
|
public async Task<bool> Confirm()
|
||||||
|
{
|
||||||
|
await Publisher.Publish(Create.As(new Vault(Name)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public partial class FooterViewModel :
|
||||||
|
ObservableCollectionViewModel<IMainNavigationViewModel>
|
||||||
|
{
|
||||||
|
public FooterViewModel(IServiceProvider serviceProvider,
|
||||||
|
IServiceFactory serviceFactory,
|
||||||
|
IPublisher publisher,
|
||||||
|
ISubscriber subscriber,
|
||||||
|
IDisposer disposer) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||||
|
{
|
||||||
|
Add<ManageNavigationViewModel>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
namespace Bitvault
|
||||||
|
{
|
||||||
|
public interface IVaultFactory
|
||||||
|
{
|
||||||
|
Task CreateAsync(string name, VaultConfiguration configuration);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,11 +7,10 @@ public class LockViewModel(IServiceProvider serviceProvider,
|
|||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer) :
|
IDisposer disposer) :
|
||||||
ObservableViewModel(serviceProvider, serviceFactory, publisher, subscriber, disposer),
|
ObservableViewModel(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||||
IConfirmation
|
|
||||||
{
|
{
|
||||||
public Task<bool> Confirm()
|
//public Task<bool> Confirm()
|
||||||
{
|
//{
|
||||||
return Task.FromResult(false);
|
// //return Task.FromResult(false);
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Toolkit.Foundation;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
@@ -6,14 +7,19 @@ namespace Bitvault;
|
|||||||
public partial class MainViewModel :
|
public partial class MainViewModel :
|
||||||
ObservableCollectionViewModel<IMainNavigationViewModel>
|
ObservableCollectionViewModel<IMainNavigationViewModel>
|
||||||
{
|
{
|
||||||
|
[ObservableProperty]
|
||||||
|
private FooterViewModel footer;
|
||||||
|
|
||||||
public MainViewModel(IServiceProvider serviceProvider,
|
public MainViewModel(IServiceProvider serviceProvider,
|
||||||
IServiceFactory serviceFactory,
|
IServiceFactory serviceFactory,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
IContentTemplate template) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
IContentTemplate template,
|
||||||
|
FooterViewModel footer) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||||
{
|
{
|
||||||
Template = template;
|
Template = template;
|
||||||
|
Footer = footer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IContentTemplate Template { get; set; }
|
public IContentTemplate Template { get; set; }
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public partial class ManageNavigationViewModel :
|
||||||
|
ObservableViewModel,
|
||||||
|
IMainNavigationViewModel
|
||||||
|
{
|
||||||
|
public ManageNavigationViewModel(IServiceProvider serviceProvider,
|
||||||
|
IServiceFactory serviceFactory,
|
||||||
|
IPublisher publisher,
|
||||||
|
ISubscriber subscriber,
|
||||||
|
IDisposer disposer) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using Avalonia.Styling;
|
||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public partial class ManageViewModel :
|
||||||
|
ObservableCollectionViewModel,
|
||||||
|
IMainNavigationViewModel
|
||||||
|
{
|
||||||
|
public ManageViewModel(IServiceProvider serviceProvider,
|
||||||
|
IServiceFactory serviceFactory,
|
||||||
|
IPublisher publisher,
|
||||||
|
ISubscriber subscriber,
|
||||||
|
IDisposer disposer,
|
||||||
|
IContentTemplate template) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||||
|
{
|
||||||
|
Template = template;
|
||||||
|
|
||||||
|
Add<CreateVaultNavigationViewModel>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IContentTemplate Template { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public record Vault(string Name);
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Toolkit.Foundation;
|
|
||||||
|
|
||||||
namespace Bitvault;
|
|
||||||
|
|
||||||
public class VaultComponentsInitializer(IServiceProvider provider,
|
|
||||||
IProxyServiceCollection<IComponentBuilder> proxy,
|
|
||||||
IEnumerable<IConfigurationDescriptor<VaultConfiguration>> configurations,
|
|
||||||
IComponentScopeCollection scopes,
|
|
||||||
IVaultHostCollection vaults) : IInitializer
|
|
||||||
{
|
|
||||||
public async Task Initialize()
|
|
||||||
{
|
|
||||||
foreach (IConfigurationDescriptor<VaultConfiguration> configuration in configurations)
|
|
||||||
{
|
|
||||||
if (provider.GetRequiredService<IVaultComponent>() is IVaultComponent component)
|
|
||||||
{
|
|
||||||
IComponentBuilder builder = component.Create();
|
|
||||||
builder.AddServices(services =>
|
|
||||||
{
|
|
||||||
services.AddTransient(_ =>
|
|
||||||
provider.GetRequiredService<IProxyService<IPublisher>>());
|
|
||||||
|
|
||||||
services.AddTransient(_ =>
|
|
||||||
provider.GetRequiredService<IProxyService<IComponentHostCollection>>());
|
|
||||||
|
|
||||||
services.AddScoped(_ =>
|
|
||||||
provider.GetRequiredService<INavigationContextCollection>());
|
|
||||||
|
|
||||||
services.AddScoped(_ =>
|
|
||||||
provider.GetRequiredService<INavigationContextProvider>());
|
|
||||||
|
|
||||||
services.AddScoped(_ =>
|
|
||||||
provider.GetRequiredService<IComponentScopeCollection>());
|
|
||||||
|
|
||||||
services.AddTransient(_ =>
|
|
||||||
provider.GetRequiredService<IComponentScopeProvider>());
|
|
||||||
|
|
||||||
services.AddRange(proxy.Services);
|
|
||||||
|
|
||||||
services.AddSingleton(new ComponentScope(configuration.Section));
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.AddConfiguration(configuration.Section, configuration.Value);
|
|
||||||
IComponentHost host = builder.Build();
|
|
||||||
|
|
||||||
scopes.Add(new ComponentScopeDescriptor(configuration.Section,
|
|
||||||
host.Services.GetRequiredService<IServiceProvider>()));
|
|
||||||
|
|
||||||
vaults.Add(host);
|
|
||||||
await host.StartAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public class VaultConfigurationInitializer(IEnumerable<IConfigurationDescriptor<VaultConfiguration>> configurations,
|
||||||
|
IVaultFactory factory) : IInitializer
|
||||||
|
{
|
||||||
|
public async Task Initialize()
|
||||||
|
{
|
||||||
|
foreach (IConfigurationDescriptor<VaultConfiguration> configuration in configurations)
|
||||||
|
{
|
||||||
|
await factory.CreateAsync(configuration.Section,
|
||||||
|
configuration.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public class VaultFactory(IServiceProvider provider,
|
||||||
|
IProxyServiceCollection<IComponentBuilder> proxy,
|
||||||
|
IComponentScopeCollection scopes,
|
||||||
|
IVaultHostCollection vaults) : IVaultFactory
|
||||||
|
{
|
||||||
|
public async Task CreateAsync(string name,
|
||||||
|
VaultConfiguration configuration)
|
||||||
|
{
|
||||||
|
if (provider.GetRequiredService<IVaultComponent>() is IVaultComponent component)
|
||||||
|
{
|
||||||
|
IComponentBuilder builder = component.Create();
|
||||||
|
builder.AddServices(services =>
|
||||||
|
{
|
||||||
|
services.AddTransient(_ =>
|
||||||
|
provider.GetRequiredService<IProxyService<IPublisher>>());
|
||||||
|
|
||||||
|
services.AddTransient(_ =>
|
||||||
|
provider.GetRequiredService<IProxyService<IComponentHostCollection>>());
|
||||||
|
|
||||||
|
services.AddScoped(_ =>
|
||||||
|
provider.GetRequiredService<INavigationContextCollection>());
|
||||||
|
|
||||||
|
services.AddScoped(_ =>
|
||||||
|
provider.GetRequiredService<INavigationContextProvider>());
|
||||||
|
|
||||||
|
services.AddScoped(_ =>
|
||||||
|
provider.GetRequiredService<IComponentScopeCollection>());
|
||||||
|
|
||||||
|
services.AddTransient(_ =>
|
||||||
|
provider.GetRequiredService<IComponentScopeProvider>());
|
||||||
|
|
||||||
|
services.AddRange(proxy.Services);
|
||||||
|
services.AddSingleton(new ComponentScope(name));
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.AddConfiguration(name, configuration);
|
||||||
|
IComponentHost host = builder.Build();
|
||||||
|
|
||||||
|
scopes.Add(new ComponentScopeDescriptor(name,
|
||||||
|
host.Services.GetRequiredService<IServiceProvider>()));
|
||||||
|
|
||||||
|
vaults.Add(host);
|
||||||
|
await host.StartAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public class VaultHandler(IVaultFactory factory) : INotificationHandler<Create<Vault>>
|
||||||
|
{
|
||||||
|
public async Task Handle(Create<Vault> args,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
if (args.Value is Vault vault)
|
||||||
|
{
|
||||||
|
await factory.CreateAsync($"Vault:{vault.Name}", new VaultConfiguration { Name = vault.Name });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user