diff --git a/src/core/DigitalData.MessagingService.Application/DependencyInjection/DependencyInjection.cs b/src/core/DigitalData.MessagingService.Application/DependencyInjection/DependencyInjection.cs index 000e580..74af05c 100644 --- a/src/core/DigitalData.MessagingService.Application/DependencyInjection/DependencyInjection.cs +++ b/src/core/DigitalData.MessagingService.Application/DependencyInjection/DependencyInjection.cs @@ -1,6 +1,5 @@ #if NET using FluentValidation; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System.Reflection; @@ -11,25 +10,21 @@ namespace DigitalData.MessagingService.Application.DependencyInjection; /// public static class DependencyInjection { - public static IServiceCollection AddMessagingServiceApplication(this IServiceCollection services, Action configure) + public static IServiceCollection AddMessagingServiceApplication(this IServiceCollection services, string luckyPennySoftLicenseKey) { var assembly = Assembly.GetExecutingAssembly(); - var configuration = new MessagingServiceApplicationConfiguration(services); - configure(configuration); - configuration.EnsureConfigured(); - // MediatR - Register all handlers services.AddMediatR(config => { - config.LicenseKey = configuration.LuckyPennySoftLicenseKey; + config.LicenseKey = luckyPennySoftLicenseKey; config.RegisterServicesFromAssembly(assembly); }); // AutoMapper - Use built-in DI extension (AutoMapper 16.2.0+) services.AddAutoMapper(config => { - config.LicenseKey = configuration.LuckyPennySoftLicenseKey; + config.LicenseKey = luckyPennySoftLicenseKey; config.AddMaps(assembly); }); diff --git a/src/core/DigitalData.MessagingService.Application/DependencyInjection/MessagingServiceApplicationConfiguration.cs b/src/core/DigitalData.MessagingService.Application/DependencyInjection/MessagingServiceApplicationConfiguration.cs deleted file mode 100644 index d0e6cf3..0000000 --- a/src/core/DigitalData.MessagingService.Application/DependencyInjection/MessagingServiceApplicationConfiguration.cs +++ /dev/null @@ -1,37 +0,0 @@ -#if NET -using Microsoft.Extensions.Configuration; - -namespace DigitalData.MessagingService.Application.DependencyInjection; - -public partial class MessagingServiceApplicationConfiguration -{ - private bool _luckyPennySoftLicenseKeyAdded = false; - - internal void EnsureConfigured() - { - if (!_luckyPennySoftLicenseKeyAdded) - { - throw new InvalidOperationException("LuckyPennySoftLicenseKey is not configured. Please call SetLuckyPennySoftLicenseKey() or SetLuckyPennySoftLicenseKey(IConfiguration) in DI configuration."); - } - } - - #region LuckyPennySoftLicenseKey - internal string? LuckyPennySoftLicenseKey { get; set; } = null; - - public MessagingServiceApplicationConfiguration SetLuckyPennySoftLicenseKey(string licenseKey) - { - if (string.IsNullOrWhiteSpace(licenseKey)) - throw new InvalidOperationException("LuckyPennySoftLicenseKey is not configured. Please call SetLuckyPennySoftLicenseKey() or SetLuckyPennySoftLicenseKey(IConfiguration) in DI configuration."); - - LuckyPennySoftLicenseKey = licenseKey; - _luckyPennySoftLicenseKeyAdded = true; - return this; - } - - public MessagingServiceApplicationConfiguration SetLuckyPennySoftLicenseKey(IConfiguration configuration, string key = "LuckyPennySoftLicenseKey") - { - return SetLuckyPennySoftLicenseKey(configuration.GetValue(key) ?? string.Empty); - } - #endregion LuckyPennySoftLicenseKey -} -#endif \ No newline at end of file diff --git a/src/presentation/DigitalData.MessagingService.API/Program.cs b/src/presentation/DigitalData.MessagingService.API/Program.cs index eaa280b..3664458 100644 --- a/src/presentation/DigitalData.MessagingService.API/Program.cs +++ b/src/presentation/DigitalData.MessagingService.API/Program.cs @@ -65,7 +65,9 @@ try builder.Configuration.AddJsonFile("appsettings.Secrets.json", optional: true, reloadOnChange: true); // Register Application layer (MediatR, AutoMapper, FluentValidation) - builder.Services.AddMessagingServiceApplication(cfg => cfg.SetLuckyPennySoftLicenseKey(builder.Configuration)); + var LuckyPennySoftLicenseKey = builder.Configuration.GetValue("LuckyPennySoftLicenseKey") + ?? throw new InvalidOperationException("The required configuration value 'LuckyPennySoftLicenseKey' is missing. Please ensure it is properly configured."); + builder.Services.AddMessagingServiceApplication(LuckyPennySoftLicenseKey); // Register Infrastructure layer (RabbitMQ, Repositories, etc.) builder.Services.AddInfrastructure(cfg => cfg