refactor(application)!: accept license key directly in AddMessagingServiceApplication
Remove MessagingServiceApplicationConfiguration and pass the LuckyPennySoft license key as a string. Program.cs now reads the value from configuration and fails fast with a clear error when it is missing. BREAKING CHANGE: AddMessagingServiceApplication now takes a license key string.
This commit is contained in:
@@ -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;
|
||||
/// </summary>
|
||||
public static class DependencyInjection
|
||||
{
|
||||
public static IServiceCollection AddMessagingServiceApplication(this IServiceCollection services, Action<MessagingServiceApplicationConfiguration> 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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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<string>(key) ?? string.Empty);
|
||||
}
|
||||
#endregion LuckyPennySoftLicenseKey
|
||||
}
|
||||
#endif
|
||||
@@ -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<string>("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
|
||||
|
||||
Reference in New Issue
Block a user