From 37ba85d6815699bccf0191ee5719a68fd3081a3b Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 25 Mar 2026 13:26:54 +0100 Subject: [PATCH] Add support for configuring DbModelOptions via DI Introduce ConfigureDbModel methods to DependencyInjection for setting up DbModelOptions from code or configuration. Update required services tracking and add usage in Program.cs to enable structured DbModelOptions injection. --- src/ReC.API/Program.cs | 1 + src/ReC.Application/DependencyInjection.cs | 28 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) 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 } }