Added ConfigurationBuilder

This commit is contained in:
TheXamlGuy
2024-10-08 09:43:09 +01:00
parent f47e3deee9
commit 55756b7093
6 changed files with 55 additions and 36 deletions
+12 -6
View File
@@ -7,16 +7,17 @@ public class ComponentFactory(IServiceProvider provider,
IComponentScopeCollection scopes) :
IComponentFactory
{
public IComponentHost? Create<TComponent, TConfiguration>(string name,
TConfiguration? configuration = null,
Action<IComponentBuilder>? builderDelegate = null,
public IComponentHost? Create<TComponent, TConfiguration>(string key,
Action<IConfigurationBuilder<TConfiguration>>? configurationDelegate = null,
Action<IComponentBuilder>? componentDelegate = null,
Action<IServiceCollection>? servicesDelegate = null)
where TComponent : IComponent
where TConfiguration : class, new()
{
if (provider.GetRequiredService<TComponent>() is TComponent component)
{
IComponentBuilder builder = component.Configure(name, configuration, builderDelegate);
IComponentBuilder builder = component.Configure(configurationDelegate,
componentDelegate);
builder.AddServices(services =>
{
@@ -45,12 +46,17 @@ 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)
{
servicesDelegate(services);
}
});
IComponentHost host = builder.Build();
scopes.Add(new ComponentScopeDescriptor(name,
scopes.Add(new ComponentScopeDescriptor(key,
host.Services.GetRequiredService<IServiceProvider>()));
return host;