using System.Reflection; using FluentValidation; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace DigitalData.MessagingService.Application; /// /// Dependency injection configuration for Application layer. /// public static class DependencyInjection { 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 - 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); return services; } }