From c4a9fb4159752e6707fefe022c8fa60e1cd4958a Mon Sep 17 00:00:00 2001 From: DavidEggenberger Date: Mon, 18 Mar 2024 19:36:23 +0100 Subject: [PATCH] registrating configuration with valid name --- .../Features/EFCore/Configuration/EFCoreConfiguration.cs | 6 ++++-- Source/Shared/Features/EFCore/Registrator.cs | 7 +++---- .../Shared/Features/Modules/Configuration/Registrator.cs | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Source/Shared/Features/EFCore/Configuration/EFCoreConfiguration.cs b/Source/Shared/Features/EFCore/Configuration/EFCoreConfiguration.cs index 977f124f..bdfbd7a1 100644 --- a/Source/Shared/Features/EFCore/Configuration/EFCoreConfiguration.cs +++ b/Source/Shared/Features/EFCore/Configuration/EFCoreConfiguration.cs @@ -1,6 +1,8 @@ -namespace Shared.Features.EFCore.Configuration +using Shared.Features.Modules.Configuration; + +namespace Shared.Features.EFCore.Configuration { - public class EFCoreConfiguration + public class EFCoreConfiguration : IModuleConfiguration { public string SQLServerConnectionString_Dev { get; set; } public string SQLServerConnectionString_Prod { get; set; } diff --git a/Source/Shared/Features/EFCore/Registrator.cs b/Source/Shared/Features/EFCore/Registrator.cs index 098460fb..5394ff52 100644 --- a/Source/Shared/Features/EFCore/Registrator.cs +++ b/Source/Shared/Features/EFCore/Registrator.cs @@ -1,8 +1,8 @@ using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; using Shared.Features.EFCore.Configuration; +using Shared.Features.Modules.Configuration; namespace Shared.Features.EFCore { @@ -10,9 +10,8 @@ public static class Registrator { public static IServiceCollection AddEFCore(this IServiceCollection services, IConfiguration configuration) { - services.Configure(configuration.GetSection(nameof(EFCoreConfiguration))); - services.AddScoped(sp => sp.GetRequiredService>().Value); - services.AddSingleton, EFCoreConfigurationValidator>(); + services.RegisterModuleConfiguration(configuration); + services.AddScoped(); return services; } diff --git a/Source/Shared/Features/Modules/Configuration/Registrator.cs b/Source/Shared/Features/Modules/Configuration/Registrator.cs index 3ec1dd5c..f039d65b 100644 --- a/Source/Shared/Features/Modules/Configuration/Registrator.cs +++ b/Source/Shared/Features/Modules/Configuration/Registrator.cs @@ -12,7 +12,7 @@ public static class Registrator services.AddScoped(sp => { TModuleConfiguration sc = new TModuleConfiguration(); - sp.GetRequiredService().GetSection(nameof(TModuleConfiguration)).Bind(sc); + sp.GetRequiredService().GetSection(typeof(TModuleConfiguration).Name).Bind(sc); return sc; }); @@ -25,7 +25,7 @@ public static class Registrator services.AddScoped(sp => { TModuleConfiguration sc = new TModuleConfiguration(); - sp.GetRequiredService().GetSection(nameof(TModuleConfiguration)).Bind(sc); + sp.GetRequiredService().GetSection(typeof(TModuleConfiguration).Name).Bind(sc); return sc; });