Amend compoments to be keyed based

This commit is contained in:
TheXamlGuy
2024-06-29 11:23:44 +01:00
parent 4e377b35d1
commit 46b5931484
7 changed files with 24 additions and 14 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ public partial class App : Application
} }
services.AddHandler<WalletActivatedHandler>(); services.AddHandler<WalletActivatedHandler>();
services.AddTransient<IWalletComponent>(provider => Component.Register<WalletComponent>(provider, args => services.AddTransient(provider => Component.Create<WalletComponent>(provider, args =>
{ {
args.AddServices(services => args.AddServices(services =>
{ {
-5
View File
@@ -1,5 +0,0 @@
using Toolkit.Foundation;
namespace Wallet;
public interface IWalletComponent : IComponent;
+1 -1
View File
@@ -4,6 +4,6 @@ namespace Wallet
{ {
public interface IWalletFactory public interface IWalletFactory
{ {
IComponentHost? Create(string name); IComponentHost? Create(string key);
} }
} }
+17 -3
View File
@@ -1,6 +1,20 @@
using Toolkit.Foundation; using Microsoft.Extensions.Hosting;
using Toolkit.Foundation;
namespace Wallet; namespace Wallet;
public class WalletComponent(IComponentBuilder builder) : Component(builder), public class WalletComponent(IHostEnvironment environment,
IWalletComponent; IComponentBuilder builder) :
Component(builder)
{
public override IComponentBuilder Configuring(string key,
IComponentBuilder builder)
{
builder.SetComponentConfiguration(args =>
{
args.ContentRoot = Path.Combine(environment.ContentRootPath, key.Replace(":", "\\"));
});
return base.Configuring(key, builder);
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
namespace Wallet; namespace Wallet;
public class WalletConnection(string connection) public record WalletConnection(string connection)
{ {
private readonly string connection = connection; private readonly string connection = connection;
+3 -2
View File
@@ -5,9 +5,10 @@ namespace Wallet;
public class WalletFactory(IComponentFactory componentFactory) : public class WalletFactory(IComponentFactory componentFactory) :
IWalletFactory IWalletFactory
{ {
public IComponentHost? Create(string name) public IComponentHost? Create(string key)
{ {
if (componentFactory.Create<IWalletComponent, WalletConfiguration>($"Wallet:{name}", new WalletConfiguration()) is IComponentHost host) if (componentFactory.Create<WalletComponent, WalletConfiguration>($"Wallet:{key}",
new WalletConfiguration()) is IComponentHost host)
{ {
return host; return host;
} }
+1 -1
View File
@@ -11,7 +11,7 @@ public class WalletInitializer(IEnumerable<IConfigurationDescriptor<WalletConfig
{ {
foreach (IConfigurationDescriptor<WalletConfiguration> configuration in configurations) foreach (IConfigurationDescriptor<WalletConfiguration> configuration in configurations)
{ {
if (componentFactory.Create<IWalletComponent, if (componentFactory.Create<WalletComponent,
WalletConfiguration>(configuration.Section, configuration.Value) WalletConfiguration>(configuration.Section, configuration.Value)
is IComponentHost host) is IComponentHost host)
{ {