Refactored `EmailAccountDto` to represent a single account with immutable properties and added an `Id` field. Introduced `EmailAccountsOptions` to manage multiple accounts and bound it to the `EmailAccounts` configuration section. Updated `DependencyInjection` to register `EmailAccountsOptions` and removed the old single-account binding. Refactored `LimilabsEmailService` to use `EmailAccountsOptions` and select the appropriate account dynamically. Replaced the `EmailAccount` section in `appsettings.Secrets.json` with a new `EmailAccounts` section supporting multiple accounts. Added a package reference for `Microsoft.Extensions.Options. ConfigurationExtensions` to support the options pattern.
46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using DigitalData.MessagingService.Application.Common.Options;
|
|
using FluentValidation;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
using System.Reflection;
|
|
|
|
namespace DigitalData.MessagingService.Application;
|
|
|
|
/// <summary>
|
|
/// Dependency injection configuration for Application layer.
|
|
/// </summary>
|
|
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<string>("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);
|
|
|
|
// Register EmailAccounts configuration (IOptions<EmailAccountsOptions>)
|
|
services.Configure<EmailAccountsOptions>(configuration.GetSection(EmailAccountsOptions.SectionName));
|
|
|
|
return services;
|
|
}
|
|
}
|