Skip to content

Commit

Permalink
registrating configuration with valid name
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidEggenberger committed Mar 18, 2024
1 parent bdf5931 commit c4a9fb4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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; }
Expand Down
7 changes: 3 additions & 4 deletions Source/Shared/Features/EFCore/Registrator.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
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
{
public static class Registrator
{
public static IServiceCollection AddEFCore(this IServiceCollection services, IConfiguration configuration)
{
services.Configure<EFCoreConfiguration>(configuration.GetSection(nameof(EFCoreConfiguration)));
services.AddScoped(sp => sp.GetRequiredService<IOptions<EFCoreConfiguration>>().Value);
services.AddSingleton<IValidateOptions<EFCoreConfiguration>, EFCoreConfigurationValidator>();
services.RegisterModuleConfiguration<EFCoreConfiguration, EFCoreConfigurationValidator>(configuration);
services.AddScoped<TransactionScopeMiddleware>();

return services;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Shared/Features/Modules/Configuration/Registrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class Registrator
services.AddScoped<TModuleConfiguration>(sp =>
{
TModuleConfiguration sc = new TModuleConfiguration();
sp.GetRequiredService<IConfiguration>().GetSection(nameof(TModuleConfiguration)).Bind(sc);
sp.GetRequiredService<IConfiguration>().GetSection(typeof(TModuleConfiguration).Name).Bind(sc);
return sc;
});

Expand All @@ -25,7 +25,7 @@ public static class Registrator
services.AddScoped<TModuleConfiguration>(sp =>
{
TModuleConfiguration sc = new TModuleConfiguration();
sp.GetRequiredService<IConfiguration>().GetSection(nameof(TModuleConfiguration)).Bind(sc);
sp.GetRequiredService<IConfiguration>().GetSection(typeof(TModuleConfiguration).Name).Bind(sc);
return sc;
});

Expand Down

0 comments on commit c4a9fb4

Please sign in to comment.