diff --git a/Toolkit.Foundation/Component.cs b/Toolkit.Foundation/Component.cs index f36c579..68df7e3 100644 --- a/Toolkit.Foundation/Component.cs +++ b/Toolkit.Foundation/Component.cs @@ -10,19 +10,16 @@ public class Component : protected Component(IComponentBuilder builder) => this.builder = builder; - public static TComponent? Create(IServiceProvider provider, + public static TComponent Create(IServiceProvider provider, Action builderDelegate) where TComponent : class, IComponent { - if (provider.GetRequiredService() is IServiceFactory factory) - { - IComponentBuilder builder = ComponentBuilder.Create(); - builderDelegate(builder); + IServiceFactory factory = provider.GetRequiredService(); - return factory.Create(builder); - } + IComponentBuilder builder = ComponentBuilder.Create(); + builderDelegate(builder); - return default; + return factory.Create(builder); } public IComponentBuilder Configure(string name) => diff --git a/Toolkit.Foundation/ComponentBuilder.cs b/Toolkit.Foundation/ComponentBuilder.cs index 5cc39b0..5aedfa8 100644 --- a/Toolkit.Foundation/ComponentBuilder.cs +++ b/Toolkit.Foundation/ComponentBuilder.cs @@ -96,10 +96,10 @@ public class ComponentBuilder : return host.Services.GetRequiredService(); } - public void SetComponentConfiguration(Action configurationDelegate) + public void SetContentConfiguration(Action configurationDelegate) { ComponentContentConfiguration configuration = new(); - configurationDelegate.Invoke(configuration); + configurationDelegate(configuration); this.configuration = configuration; } diff --git a/Toolkit.Foundation/ComponentFactory.cs b/Toolkit.Foundation/ComponentFactory.cs index 872e55e..25f36e5 100644 --- a/Toolkit.Foundation/ComponentFactory.cs +++ b/Toolkit.Foundation/ComponentFactory.cs @@ -9,6 +9,7 @@ public class ComponentFactory(IServiceProvider provider, { public IComponentHost? Create(string key, TConfiguration? configuration = null, + Action? builderDelegate = null, Action? servicesDelegate = null) where TComponent : IComponent where TConfiguration : @@ -17,6 +18,12 @@ public class ComponentFactory(IServiceProvider provider, if (provider.GetRequiredService() is TComponent component) { IComponentBuilder builder = component.Configure(key); + + if (builderDelegate is not null) + { + builderDelegate(builder); + } + builder.AddServices(services => { services.AddTransient(_ => diff --git a/Toolkit.Foundation/IComponentBuilder.cs b/Toolkit.Foundation/IComponentBuilder.cs index fc8fafa..cf0e855 100644 --- a/Toolkit.Foundation/IComponentBuilder.cs +++ b/Toolkit.Foundation/IComponentBuilder.cs @@ -18,5 +18,5 @@ public interface IComponentBuilder IComponentHost Build(); - void SetComponentConfiguration(Action configurationDelegate); + void SetContentConfiguration(Action configurationDelegate); } \ No newline at end of file diff --git a/Toolkit.Foundation/IComponentFactory.cs b/Toolkit.Foundation/IComponentFactory.cs index 928e3f6..c6c63e4 100644 --- a/Toolkit.Foundation/IComponentFactory.cs +++ b/Toolkit.Foundation/IComponentFactory.cs @@ -6,6 +6,7 @@ public interface IComponentFactory { IComponentHost? Create(string name, TConfiguration? configuration = null, + Action? builderDelegate = null, Action? servicesDelegate = null) where TComponent : IComponent where TConfiguration : ComponentConfiguration, new();