remove the hard requirement to use ComponentConfig
This commit is contained in:
@@ -50,7 +50,8 @@ public class ComponentBuilder :
|
|||||||
public static IComponentBuilder Create() => new ComponentBuilder();
|
public static IComponentBuilder Create() => new ComponentBuilder();
|
||||||
|
|
||||||
public IComponentBuilder AddConfiguration<TConfiguration>(Action<TConfiguration> configurationDelegate)
|
public IComponentBuilder AddConfiguration<TConfiguration>(Action<TConfiguration> configurationDelegate)
|
||||||
where TConfiguration : ComponentConfiguration, new()
|
where TConfiguration :
|
||||||
|
class, new()
|
||||||
{
|
{
|
||||||
TConfiguration configuration = new();
|
TConfiguration configuration = new();
|
||||||
if (configurationDelegate is not null)
|
if (configurationDelegate is not null)
|
||||||
@@ -65,7 +66,7 @@ public class ComponentBuilder :
|
|||||||
public IComponentBuilder AddConfiguration<TConfiguration>(string section,
|
public IComponentBuilder AddConfiguration<TConfiguration>(string section,
|
||||||
TConfiguration? configuration = null)
|
TConfiguration? configuration = null)
|
||||||
where TConfiguration :
|
where TConfiguration :
|
||||||
ComponentConfiguration, new()
|
class, new()
|
||||||
{
|
{
|
||||||
hostBuilder.AddConfiguration(section: section, path: ConfigurationFile,
|
hostBuilder.AddConfiguration(section: section, path: ConfigurationFile,
|
||||||
defaultConfiguration: configuration);
|
defaultConfiguration: configuration);
|
||||||
@@ -74,7 +75,8 @@ public class ComponentBuilder :
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IComponentBuilder AddConfiguration<TConfiguration>(string section)
|
public IComponentBuilder AddConfiguration<TConfiguration>(string section)
|
||||||
where TConfiguration : ComponentConfiguration, new()
|
where TConfiguration :
|
||||||
|
class, new()
|
||||||
{
|
{
|
||||||
AddConfiguration<TConfiguration>(section, null);
|
AddConfiguration<TConfiguration>(section, null);
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Toolkit.Foundation;
|
|
||||||
|
|
||||||
public record ComponentConfiguration;
|
|
||||||
@@ -13,7 +13,7 @@ public class ComponentFactory(IServiceProvider provider,
|
|||||||
Action<IServiceCollection>? servicesDelegate = null)
|
Action<IServiceCollection>? servicesDelegate = null)
|
||||||
where TComponent : IComponent
|
where TComponent : IComponent
|
||||||
where TConfiguration :
|
where TConfiguration :
|
||||||
ComponentConfiguration, new()
|
class, new()
|
||||||
{
|
{
|
||||||
if (provider.GetRequiredService<TComponent>() is TComponent component)
|
if (provider.GetRequiredService<TComponent>() is TComponent component)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class ComponentHost(IServiceProvider services,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TConfiguration? GetConfiguration<TConfiguration>()
|
public TConfiguration? GetConfiguration<TConfiguration>()
|
||||||
where TConfiguration : ComponentConfiguration
|
where TConfiguration : class
|
||||||
{
|
{
|
||||||
return Services.GetService<TConfiguration>();
|
return Services.GetService<TConfiguration>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ public interface IComponentBuilder
|
|||||||
string ContentRoot { get; set; }
|
string ContentRoot { get; set; }
|
||||||
|
|
||||||
IComponentBuilder AddConfiguration<TConfiguration>(Action<TConfiguration> configurationDelegate)
|
IComponentBuilder AddConfiguration<TConfiguration>(Action<TConfiguration> configurationDelegate)
|
||||||
where TConfiguration : ComponentConfiguration, new();
|
where TConfiguration : class, new();
|
||||||
|
|
||||||
IComponentBuilder AddConfiguration<TConfiguration>(string section,
|
IComponentBuilder AddConfiguration<TConfiguration>(string section,
|
||||||
TConfiguration? configuration = null)
|
TConfiguration? configuration = null)
|
||||||
where TConfiguration : ComponentConfiguration, new();
|
where TConfiguration : class, new();
|
||||||
|
|
||||||
IComponentBuilder AddConfiguration<TConfiguration>(string section)
|
IComponentBuilder AddConfiguration<TConfiguration>(string section)
|
||||||
where TConfiguration : ComponentConfiguration, new();
|
where TConfiguration : class, new();
|
||||||
|
|
||||||
IComponentBuilder AddServices(Action<IServiceCollection> configureDelegate);
|
IComponentBuilder AddServices(Action<IServiceCollection> configureDelegate);
|
||||||
|
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ public interface IComponentFactory
|
|||||||
Action<IComponentBuilder>? builderDelegate = null,
|
Action<IComponentBuilder>? builderDelegate = null,
|
||||||
Action<IServiceCollection>? servicesDelegate = null)
|
Action<IServiceCollection>? servicesDelegate = null)
|
||||||
where TComponent : IComponent
|
where TComponent : IComponent
|
||||||
where TConfiguration : ComponentConfiguration, new();
|
where TConfiguration : class, new();
|
||||||
}
|
}
|
||||||
@@ -5,5 +5,7 @@ namespace Toolkit.Foundation;
|
|||||||
public interface IComponentHost :
|
public interface IComponentHost :
|
||||||
IHost
|
IHost
|
||||||
{
|
{
|
||||||
TConfiguration? GetConfiguration<TConfiguration>() where TConfiguration : ComponentConfiguration;
|
TConfiguration? GetConfiguration<TConfiguration>()
|
||||||
|
where TConfiguration :
|
||||||
|
class;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user