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 IComponentBuilder AddConfiguration<TConfiguration>(Action<TConfiguration> configurationDelegate)
|
||||
where TConfiguration : ComponentConfiguration, new()
|
||||
where TConfiguration :
|
||||
class, new()
|
||||
{
|
||||
TConfiguration configuration = new();
|
||||
if (configurationDelegate is not null)
|
||||
@@ -65,7 +66,7 @@ public class ComponentBuilder :
|
||||
public IComponentBuilder AddConfiguration<TConfiguration>(string section,
|
||||
TConfiguration? configuration = null)
|
||||
where TConfiguration :
|
||||
ComponentConfiguration, new()
|
||||
class, new()
|
||||
{
|
||||
hostBuilder.AddConfiguration(section: section, path: ConfigurationFile,
|
||||
defaultConfiguration: configuration);
|
||||
@@ -74,7 +75,8 @@ public class ComponentBuilder :
|
||||
}
|
||||
|
||||
public IComponentBuilder AddConfiguration<TConfiguration>(string section)
|
||||
where TConfiguration : ComponentConfiguration, new()
|
||||
where TConfiguration :
|
||||
class, new()
|
||||
{
|
||||
AddConfiguration<TConfiguration>(section, null);
|
||||
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)
|
||||
where TComponent : IComponent
|
||||
where TConfiguration :
|
||||
ComponentConfiguration, new()
|
||||
class, new()
|
||||
{
|
||||
if (provider.GetRequiredService<TComponent>() is TComponent component)
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@ public class ComponentHost(IServiceProvider services,
|
||||
}
|
||||
|
||||
public TConfiguration? GetConfiguration<TConfiguration>()
|
||||
where TConfiguration : ComponentConfiguration
|
||||
where TConfiguration : class
|
||||
{
|
||||
return Services.GetService<TConfiguration>();
|
||||
}
|
||||
|
||||
@@ -9,14 +9,14 @@ public interface IComponentBuilder
|
||||
string ContentRoot { get; set; }
|
||||
|
||||
IComponentBuilder AddConfiguration<TConfiguration>(Action<TConfiguration> configurationDelegate)
|
||||
where TConfiguration : ComponentConfiguration, new();
|
||||
where TConfiguration : class, new();
|
||||
|
||||
IComponentBuilder AddConfiguration<TConfiguration>(string section,
|
||||
TConfiguration? configuration = null)
|
||||
where TConfiguration : ComponentConfiguration, new();
|
||||
where TConfiguration : class, new();
|
||||
|
||||
IComponentBuilder AddConfiguration<TConfiguration>(string section)
|
||||
where TConfiguration : ComponentConfiguration, new();
|
||||
where TConfiguration : class, new();
|
||||
|
||||
IComponentBuilder AddServices(Action<IServiceCollection> configureDelegate);
|
||||
|
||||
|
||||
@@ -9,5 +9,5 @@ public interface IComponentFactory
|
||||
Action<IComponentBuilder>? builderDelegate = null,
|
||||
Action<IServiceCollection>? servicesDelegate = null)
|
||||
where TComponent : IComponent
|
||||
where TConfiguration : ComponentConfiguration, new();
|
||||
where TConfiguration : class, new();
|
||||
}
|
||||
@@ -5,5 +5,7 @@ namespace Toolkit.Foundation;
|
||||
public interface IComponentHost :
|
||||
IHost
|
||||
{
|
||||
TConfiguration? GetConfiguration<TConfiguration>() where TConfiguration : ComponentConfiguration;
|
||||
TConfiguration? GetConfiguration<TConfiguration>()
|
||||
where TConfiguration :
|
||||
class;
|
||||
}
|
||||
Reference in New Issue
Block a user