remove the hard requirement to use ComponentConfig

This commit is contained in:
TheXamlGuy
2024-09-30 19:42:15 +01:00
parent 70f1908c0f
commit a9ae9b1d8f
7 changed files with 14 additions and 13 deletions
+5 -3
View File
@@ -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;
+1 -1
View File
@@ -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)
{
+1 -1
View File
@@ -16,7 +16,7 @@ public class ComponentHost(IServiceProvider services,
}
public TConfiguration? GetConfiguration<TConfiguration>()
where TConfiguration : ComponentConfiguration
where TConfiguration : class
{
return Services.GetService<TConfiguration>();
}
+3 -3
View File
@@ -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);
+1 -1
View File
@@ -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();
}
+3 -1
View File
@@ -5,5 +5,7 @@ namespace Toolkit.Foundation;
public interface IComponentHost :
IHost
{
TConfiguration? GetConfiguration<TConfiguration>() where TConfiguration : ComponentConfiguration;
TConfiguration? GetConfiguration<TConfiguration>()
where TConfiguration :
class;
}