From 4e164a916221cd83a7e69c8cdfcefb83263cce82 Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 23 Jul 2026 12:41:42 +0200 Subject: [PATCH] feat: Add LuckyPennySoft license key configuration for AutoMapper and MediatR - Add license key reading from appsettings.json - Configure AutoMapper 16.2.0+ with built-in DI extension and license key - Configure MediatR 14.2.0+ with license key - Update Program.cs to pass IConfiguration to AddApplicationServices --- src/DigitalData.EmailProfiler.API/Program.cs | 2 +- .../DependencyInjection.cs | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/DigitalData.EmailProfiler.API/Program.cs b/src/DigitalData.EmailProfiler.API/Program.cs index e64d333..6bbf8cf 100644 --- a/src/DigitalData.EmailProfiler.API/Program.cs +++ b/src/DigitalData.EmailProfiler.API/Program.cs @@ -38,7 +38,7 @@ try builder.Configuration.AddJsonFile("appsettings.Secrets.json", optional: true, reloadOnChange: true); // Register Application layer (MediatR, AutoMapper, FluentValidation) - builder.Services.AddApplicationServices(); + builder.Services.AddApplicationServices(builder.Configuration); // Register Infrastructure layer (RabbitMQ, Repositories, etc.) builder.Services.AddInfrastructure(builder.Configuration); diff --git a/src/DigitalData.EmailProfiler.Application/DependencyInjection.cs b/src/DigitalData.EmailProfiler.Application/DependencyInjection.cs index 52d918d..13176bc 100644 --- a/src/DigitalData.EmailProfiler.Application/DependencyInjection.cs +++ b/src/DigitalData.EmailProfiler.Application/DependencyInjection.cs @@ -1,5 +1,6 @@ using System.Reflection; using FluentValidation; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace DigitalData.EmailProfiler.Application; @@ -9,18 +10,27 @@ namespace DigitalData.EmailProfiler.Application; /// public static class DependencyInjection { - public static IServiceCollection AddApplicationServices(this IServiceCollection services) + public static IServiceCollection AddApplicationServices(this IServiceCollection services, IConfiguration configuration) { var assembly = Assembly.GetExecutingAssembly(); + // Read LuckyPennySoft license key from appsettings.json + var licenseKey = configuration.GetValue("LuckyPennySoftLicenseKey") + ?? throw new InvalidOperationException("LuckyPennySoftLicenseKey not found in configuration"); + // MediatR - Register all handlers services.AddMediatR(config => { + config.LicenseKey = licenseKey; config.RegisterServicesFromAssembly(assembly); }); - // AutoMapper - Register all profiles - services.AddAutoMapper(assembly); + // AutoMapper - Use built-in DI extension (AutoMapper 16.2.0+) + services.AddAutoMapper(config => + { + config.LicenseKey = licenseKey; + config.AddMaps(assembly); + }); // FluentValidation - Register all validators services.AddValidatorsFromAssembly(assembly);