Amend compoments to be keyed based

This commit is contained in:
TheXamlGuy
2024-06-29 11:23:45 +01:00
parent e19a963f8e
commit f921860fbe
9 changed files with 37 additions and 40 deletions
+7 -7
View File
@@ -7,16 +7,16 @@ public class ComponentFactory(IServiceProvider provider,
IComponentScopeCollection scopes) :
IComponentFactory
{
public IComponentHost? Create<TComponent, TConfiguration>(string name,
public IComponentHost? Create<TComponent, TConfiguration>(string key,
TConfiguration? configuration = null,
Action<IServiceCollection>? servicesDelegate = null)
where TComponent : IComponent
where TConfiguration : ComponentConfiguration, new()
where TConfiguration :
ComponentConfiguration, new()
{
if (provider.GetRequiredService<TComponent>() is TComponent component)
{
IComponentBuilder builder = component.Create();
IComponentBuilder builder = component.Configure(key);
builder.AddServices(services =>
{
services.AddTransient(_ =>
@@ -38,7 +38,7 @@ public class ComponentFactory(IServiceProvider provider,
provider.GetRequiredService<IComponentScopeProvider>());
services.AddRange(proxy.Services);
services.AddSingleton(new NamedComponent(name));
services.AddSingleton(new NamedComponent(key));
if (servicesDelegate is not null)
{
@@ -46,10 +46,10 @@ public class ComponentFactory(IServiceProvider provider,
}
});
builder.AddConfiguration(name, configuration);
builder.AddConfiguration(key, configuration);
IComponentHost host = builder.Build();
scopes.Add(new ComponentScopeDescriptor(name,
scopes.Add(new ComponentScopeDescriptor(key,
host.Services.GetRequiredService<IServiceProvider>()));
return host;