Fixes
This commit is contained in:
@@ -10,21 +10,18 @@ public class Component :
|
||||
protected Component(IComponentBuilder builder) =>
|
||||
this.builder = builder;
|
||||
|
||||
public static TComponent? Create<TComponent>(IServiceProvider provider,
|
||||
public static TComponent Create<TComponent>(IServiceProvider provider,
|
||||
Action<IComponentBuilder> builderDelegate)
|
||||
where TComponent : class, IComponent
|
||||
{
|
||||
if (provider.GetRequiredService<IServiceFactory>() is IServiceFactory factory)
|
||||
{
|
||||
IServiceFactory factory = provider.GetRequiredService<IServiceFactory>();
|
||||
|
||||
IComponentBuilder builder = ComponentBuilder.Create();
|
||||
builderDelegate(builder);
|
||||
|
||||
return factory.Create<TComponent>(builder);
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
public IComponentBuilder Configure(string name) =>
|
||||
Configuring(name, builder);
|
||||
|
||||
|
||||
@@ -96,10 +96,10 @@ public class ComponentBuilder :
|
||||
return host.Services.GetRequiredService<IComponentHost>();
|
||||
}
|
||||
|
||||
public void SetComponentConfiguration(Action<ComponentContentConfiguration> configurationDelegate)
|
||||
public void SetContentConfiguration(Action<ComponentContentConfiguration> configurationDelegate)
|
||||
{
|
||||
ComponentContentConfiguration configuration = new();
|
||||
configurationDelegate.Invoke(configuration);
|
||||
configurationDelegate(configuration);
|
||||
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ public class ComponentFactory(IServiceProvider provider,
|
||||
{
|
||||
public IComponentHost? Create<TComponent, TConfiguration>(string key,
|
||||
TConfiguration? configuration = null,
|
||||
Action<IComponentBuilder>? builderDelegate = null,
|
||||
Action<IServiceCollection>? servicesDelegate = null)
|
||||
where TComponent : IComponent
|
||||
where TConfiguration :
|
||||
@@ -17,6 +18,12 @@ public class ComponentFactory(IServiceProvider provider,
|
||||
if (provider.GetRequiredService<TComponent>() is TComponent component)
|
||||
{
|
||||
IComponentBuilder builder = component.Configure(key);
|
||||
|
||||
if (builderDelegate is not null)
|
||||
{
|
||||
builderDelegate(builder);
|
||||
}
|
||||
|
||||
builder.AddServices(services =>
|
||||
{
|
||||
services.AddTransient(_ =>
|
||||
|
||||
@@ -18,5 +18,5 @@ public interface IComponentBuilder
|
||||
|
||||
IComponentHost Build();
|
||||
|
||||
void SetComponentConfiguration(Action<ComponentContentConfiguration> configurationDelegate);
|
||||
void SetContentConfiguration(Action<ComponentContentConfiguration> configurationDelegate);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ public interface IComponentFactory
|
||||
{
|
||||
IComponentHost? Create<TComponent, TConfiguration>(string name,
|
||||
TConfiguration? configuration = null,
|
||||
Action<IComponentBuilder>? builderDelegate = null,
|
||||
Action<IServiceCollection>? servicesDelegate = null)
|
||||
where TComponent : IComponent
|
||||
where TConfiguration : ComponentConfiguration, new();
|
||||
|
||||
Reference in New Issue
Block a user