get vaults rendering on the screen
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IMainNavigationViewModel;
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IVaultHostCollection :
|
||||
IEnumerable<IComponentHost>
|
||||
{
|
||||
void Add(IComponentHost host);
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class MainViewHandler(IPublisher publisher,
|
||||
IServiceFactory factory) :
|
||||
INotificationHandler<Enumerate<IMainNavigationViewModel>>
|
||||
{
|
||||
public async Task Handle(Enumerate<IMainNavigationViewModel> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Notification(nameof(MainViewModel))]
|
||||
public partial class MainViewModel :
|
||||
ObservableCollectionViewModel<IMainNavigationViewModel>
|
||||
{
|
||||
@@ -13,7 +14,6 @@ public partial class MainViewModel :
|
||||
IContentTemplate template) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||
{
|
||||
Template = template;
|
||||
Add<VaultNavigationViewModel>();
|
||||
}
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class MainViewModelHandler(IPublisher publisher,
|
||||
IVaultHostCollection vaults) :
|
||||
INotificationHandler<Enumerate<IMainNavigationViewModel>>
|
||||
{
|
||||
public async Task Handle(Enumerate<IMainNavigationViewModel> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
foreach (IComponentHost vault in vaults)
|
||||
{
|
||||
if (vault.Services.GetRequiredService<VaultConfiguration>() is VaultConfiguration configuration)
|
||||
{
|
||||
if (vault.Services.GetRequiredService<IServiceFactory>() is IServiceFactory factory)
|
||||
{
|
||||
if (factory.Create<VaultNavigationViewModel>(configuration.Name) is VaultNavigationViewModel viewModel)
|
||||
{
|
||||
await publisher.Publish(new Create<IMainNavigationViewModel>(viewModel),
|
||||
nameof(MainViewModel), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@ namespace Bitvault;
|
||||
|
||||
public class VaultComponentsInitializer(IServiceProvider provider,
|
||||
IProxyServiceCollection<IComponentBuilder> proxy,
|
||||
IEnumerable<IConfiguration<VaultConfiguration>> configurations) : IInitializer
|
||||
IEnumerable<IConfiguration<VaultConfiguration>> configurations,
|
||||
IVaultHostCollection vaults) : IInitializer
|
||||
{
|
||||
public Task Initialize()
|
||||
{
|
||||
@@ -37,10 +38,11 @@ public class VaultComponentsInitializer(IServiceProvider provider,
|
||||
services.AddRange(proxy.Services);
|
||||
});
|
||||
|
||||
builder.AddConfiguration<VaultConfiguration>(configuration.Section);
|
||||
|
||||
builder.AddConfiguration(configuration.Section, configuration.Value);
|
||||
IComponentHost host = builder.Build();
|
||||
host.StartAsync();
|
||||
|
||||
vaults.Add(host);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using Toolkit.Foundation;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public record VaultConfiguration : ComponentConfiguration
|
||||
{
|
||||
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class VaultHostCollection :
|
||||
IVaultHostCollection
|
||||
|
||||
{
|
||||
private readonly List<IComponentHost> hosts = [];
|
||||
|
||||
public void Add(IComponentHost host)
|
||||
{
|
||||
hosts.Add(host);
|
||||
}
|
||||
|
||||
public IEnumerator<IComponentHost> GetEnumerator() =>
|
||||
hosts.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() =>
|
||||
hosts.GetEnumerator();
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Toolkit.Foundation;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
@@ -6,14 +7,19 @@ public partial class VaultNavigationViewModel :
|
||||
ObservableCollectionViewModel<IMainNavigationViewModel>,
|
||||
IMainNavigationViewModel
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string name;
|
||||
|
||||
public VaultNavigationViewModel(IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer,
|
||||
IContentTemplate template) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||
IContentTemplate template,
|
||||
string name) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||
{
|
||||
Template = template;
|
||||
Name = name;
|
||||
|
||||
Add<AllNavigationViewModel>();
|
||||
Add<StarredNavigationViewModel>();
|
||||
|
||||
Reference in New Issue
Block a user