bunch of fixes

This commit is contained in:
TheXamlGuy
2024-05-02 20:58:12 +01:00
parent e98e622003
commit 4b05abad9b
23 changed files with 115 additions and 192 deletions
+12 -9
View File
@@ -1,25 +1,28 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Toolkit.Foundation;
namespace Bitvault;
public class CreateVaultHandler(IVaultComponentFactory vaultComponentFactory) :
public class CreateVaultHandler(IVaultComponentFactory componentFactory) :
IHandler<Create<Vault>, bool>
{
public Task<bool> Handle(Create<Vault> args,
public async Task<bool> Handle(Create<Vault> args,
CancellationToken cancellationToken)
{
if (args.Value is Vault vault && vault.Name is { Length: > 0 } name && vault.Password is { Length: > 0 } password)
if (args.Value is Vault vault && vault.Name is { Length: > 0 } name &&
vault.Password is { Length: > 0 } password)
{
if (vaultComponentFactory.Create(name) is IComponentHost host)
if (componentFactory.Create(name) is IComponentHost host)
{
IVaultFactory factory = host.Services.GetRequiredService<IVaultFactory>();
factory.Create(name, password);
return Task.FromResult(true);
IVaultInitializer initializer = host.Services.GetRequiredService<IVaultInitializer>();
if (await initializer.Initialize(name, password))
{
host.Start();
}
}
}
return Task.FromResult(false);
return false;
}
}