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
+19 -20
View File
@@ -22,38 +22,37 @@ public class Component :
return factory.Create<TComponent>(builder);
}
public IComponentBuilder Configure(string name,
Action<IComponentBuilder>? builderDelegate = null)
{
if (builderDelegate is not null)
{
builderDelegate(builder);
}
return Configuring(builder);
}
public IComponentBuilder Configure(Action<IComponentBuilder>? builderDelegate = null)
public IComponentBuilder Configure(Action<IComponentBuilder>? componentDelegate = null)
{
if (builderDelegate is not null)
if (componentDelegate is not null)
{
builderDelegate(builder);
componentDelegate(builder);
}
return Configuring(builder);
}
public IComponentBuilder Configure<TConfiguration>(string name,
TConfiguration? configuration = null,
Action<IComponentBuilder>? builderDelegate = null)
public IComponentBuilder Configure<TConfiguration>(Action<IConfigurationBuilder<TConfiguration>>? configurationDelegate = null,
Action<IComponentBuilder>? componentDelegate = null)
where TConfiguration : class, new()
{
if (builderDelegate is not null)
if (componentDelegate is not null)
{
builderDelegate(builder);
componentDelegate(builder);
}
if (configurationDelegate is not null)
{
ConfigurationBuilder<TConfiguration> configurationBuilder = new();
configurationDelegate(configurationBuilder);
if (configurationBuilder.Section is { Length: > 0 } section)
{
builder.AddConfiguration(section, configurationBuilder.Configuration ?? new TConfiguration());
}
}
builder.AddConfiguration(name, configuration);
return Configuring(builder);
}