diff --git a/src/ReC.API/Program.cs b/src/ReC.API/Program.cs index 3f2becd..1a2a5e8 100644 --- a/src/ReC.API/Program.cs +++ b/src/ReC.API/Program.cs @@ -38,6 +38,7 @@ try options.LuckyPennySoftwareLicenseKey = builder.Configuration["LuckyPennySoftwareLicenseKey"]; options.ConfigureRecActions(config.GetSection("RecAction")); options.ConfigureSqlException(config.GetSection("SqlException")); + options.ConfigureDbModel(config.GetSection("DbModel")); }); builder.Services.AddRecInfrastructure(options => diff --git a/src/ReC.Application/DependencyInjection.cs b/src/ReC.Application/DependencyInjection.cs index 3edfb77..dd304d1 100644 --- a/src/ReC.Application/DependencyInjection.cs +++ b/src/ReC.Application/DependencyInjection.cs @@ -6,6 +6,7 @@ using ReC.Application.Common.Behaviors; using ReC.Application.Common.Behaviors.InvokeAction; using ReC.Application.Common.Constants; using ReC.Application.Common.Options; +using ReC.Application.Common.Options.DbModel; using ReC.Application.RecActions.Commands; using System.Reflection; @@ -56,7 +57,8 @@ public static class DependencyInjection private readonly Dictionary _requiredServices = new() { { nameof(ConfigureRecActions), false }, - { nameof(LuckyPennySoftwareLicenseKey), false } + { nameof(LuckyPennySoftwareLicenseKey), false }, + { nameof(ConfigureDbModel), false } }; internal void EnsureRequiredServices() @@ -138,5 +140,29 @@ public static class DependencyInjection return this; } #endregion ConfigureSqlException + + #region ConfigureDbModel + public ConfigurationOptions ConfigureDbModel(Action configure) + { + _configActions.Enqueue(services => services.Configure(configure)); + + if (_requiredServices[nameof(ConfigureDbModel)]) + throw new InvalidOperationException("DbModelOptions have already been configured."); + _requiredServices[nameof(ConfigureDbModel)] = true; + + return this; + } + + public ConfigurationOptions ConfigureDbModel(IConfiguration configuration) + { + _configActions.Enqueue(services => services.Configure(configuration)); + + if (_requiredServices[nameof(ConfigureDbModel)]) + throw new InvalidOperationException("DbModelOptions have already been configured."); + _requiredServices[nameof(ConfigureDbModel)] = true; + + return this; + } + #endregion ConfigureDbModel } }