From a9ae9b1d8fe0b4ad9a5d496fbe05febfc06c7d16 Mon Sep 17 00:00:00 2001 From: TheXamlGuy Date: Mon, 30 Sep 2024 19:42:15 +0100 Subject: [PATCH] remove the hard requirement to use ComponentConfig --- Toolkit.Foundation/ComponentBuilder.cs | 8 +++++--- Toolkit.Foundation/ComponentConfiguration.cs | 3 --- Toolkit.Foundation/ComponentFactory.cs | 2 +- Toolkit.Foundation/ComponentHost.cs | 2 +- Toolkit.Foundation/IComponentBuilder.cs | 6 +++--- Toolkit.Foundation/IComponentFactory.cs | 2 +- Toolkit.Foundation/IComponentHost.cs | 4 +++- 7 files changed, 14 insertions(+), 13 deletions(-) delete mode 100644 Toolkit.Foundation/ComponentConfiguration.cs diff --git a/Toolkit.Foundation/ComponentBuilder.cs b/Toolkit.Foundation/ComponentBuilder.cs index 91c6008..6e4f2df 100644 --- a/Toolkit.Foundation/ComponentBuilder.cs +++ b/Toolkit.Foundation/ComponentBuilder.cs @@ -50,7 +50,8 @@ public class ComponentBuilder : public static IComponentBuilder Create() => new ComponentBuilder(); public IComponentBuilder AddConfiguration(Action 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(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(string section) - where TConfiguration : ComponentConfiguration, new() + where TConfiguration : + class, new() { AddConfiguration(section, null); return this; diff --git a/Toolkit.Foundation/ComponentConfiguration.cs b/Toolkit.Foundation/ComponentConfiguration.cs deleted file mode 100644 index 907c0a7..0000000 --- a/Toolkit.Foundation/ComponentConfiguration.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace Toolkit.Foundation; - -public record ComponentConfiguration; \ No newline at end of file diff --git a/Toolkit.Foundation/ComponentFactory.cs b/Toolkit.Foundation/ComponentFactory.cs index 25f36e5..9008a73 100644 --- a/Toolkit.Foundation/ComponentFactory.cs +++ b/Toolkit.Foundation/ComponentFactory.cs @@ -13,7 +13,7 @@ public class ComponentFactory(IServiceProvider provider, Action? servicesDelegate = null) where TComponent : IComponent where TConfiguration : - ComponentConfiguration, new() + class, new() { if (provider.GetRequiredService() is TComponent component) { diff --git a/Toolkit.Foundation/ComponentHost.cs b/Toolkit.Foundation/ComponentHost.cs index e679a16..9517e58 100644 --- a/Toolkit.Foundation/ComponentHost.cs +++ b/Toolkit.Foundation/ComponentHost.cs @@ -16,7 +16,7 @@ public class ComponentHost(IServiceProvider services, } public TConfiguration? GetConfiguration() - where TConfiguration : ComponentConfiguration + where TConfiguration : class { return Services.GetService(); } diff --git a/Toolkit.Foundation/IComponentBuilder.cs b/Toolkit.Foundation/IComponentBuilder.cs index ce42434..6034fa0 100644 --- a/Toolkit.Foundation/IComponentBuilder.cs +++ b/Toolkit.Foundation/IComponentBuilder.cs @@ -9,14 +9,14 @@ public interface IComponentBuilder string ContentRoot { get; set; } IComponentBuilder AddConfiguration(Action configurationDelegate) - where TConfiguration : ComponentConfiguration, new(); + where TConfiguration : class, new(); IComponentBuilder AddConfiguration(string section, TConfiguration? configuration = null) - where TConfiguration : ComponentConfiguration, new(); + where TConfiguration : class, new(); IComponentBuilder AddConfiguration(string section) - where TConfiguration : ComponentConfiguration, new(); + where TConfiguration : class, new(); IComponentBuilder AddServices(Action configureDelegate); diff --git a/Toolkit.Foundation/IComponentFactory.cs b/Toolkit.Foundation/IComponentFactory.cs index c6c63e4..aa50763 100644 --- a/Toolkit.Foundation/IComponentFactory.cs +++ b/Toolkit.Foundation/IComponentFactory.cs @@ -9,5 +9,5 @@ public interface IComponentFactory Action? builderDelegate = null, Action? servicesDelegate = null) where TComponent : IComponent - where TConfiguration : ComponentConfiguration, new(); + where TConfiguration : class, new(); } \ No newline at end of file diff --git a/Toolkit.Foundation/IComponentHost.cs b/Toolkit.Foundation/IComponentHost.cs index fe46212..75586bf 100644 --- a/Toolkit.Foundation/IComponentHost.cs +++ b/Toolkit.Foundation/IComponentHost.cs @@ -5,5 +5,7 @@ namespace Toolkit.Foundation; public interface IComponentHost : IHost { - TConfiguration? GetConfiguration() where TConfiguration : ComponentConfiguration; + TConfiguration? GetConfiguration() + where TConfiguration : + class; } \ No newline at end of file