- Enhanced `AddAutoMapper` configuration for flexibility. - Replaced `IEnvelopeMailService` with `IEnvelopeNotificationService`. - Migrated from `IUserRepository` to `EGDbContext` for data access. - Updated RabbitMQ configuration to use `AddMessagingServiceHttpClient`. - Removed `AddUserManager` and `AddDispatcher` registrations. - Added conditional `FluentValidation` dependencies for target frameworks. - Upgraded `MediatR` to 14.2.0 and `AutoMapper` to 16.2.0. - Added `HtmlSanitizer` dependency. - Improved error handling and logging in `ReadOnlyController`.
53 lines
2.5 KiB
C#
53 lines
2.5 KiB
C#
using DigitalData.MessagingService.Client;
|
|
using EnvelopeGenerator.Application.Common.Interfaces.Services.Notification;
|
|
using EnvelopeGenerator.Infrastructure.Notification.Configuration;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace EnvelopeGenerator.Infrastructure.Notification;
|
|
|
|
public static class DependencyInjection
|
|
{
|
|
public static IServiceCollection AddNotificationInfrastructure(this IServiceCollection services, IConfiguration configuration, string sectionName = NotificationOptions.SectionName)
|
|
{
|
|
var ntfConfiguration = configuration.GetSection(sectionName);
|
|
services.Configure<NotificationOptions>(ntfConfiguration);
|
|
|
|
var options = ntfConfiguration.Get<NotificationOptions>()
|
|
?? throw new InvalidOperationException(
|
|
$"Failed to bind configuration section '{sectionName}' to {nameof(NotificationOptions)}. Ensure the section exists and is correctly configured.");
|
|
|
|
switch (options.ConsumerType)
|
|
{
|
|
case ConsumerType.API:
|
|
if (options.ApiUrl is string apiUrl)
|
|
services.AddMessagingServiceHttpClient(opt =>
|
|
{
|
|
opt.BaseAddress = new Uri(apiUrl);
|
|
// Additional configuration for the MessagingServiceHttpClient can be added here if needed
|
|
});
|
|
else
|
|
throw new InvalidOperationException(
|
|
$"MessagingServiceApiUrl must be provided when ClientType is set to Api in the '{sectionName}' configuration section.");
|
|
break;
|
|
case ConsumerType.RabbitMQ:
|
|
if (options.ApiUrl is string rabbitModeApiUrl)
|
|
services.AddMessagingServiceHttpClient(opt =>
|
|
{
|
|
opt.BaseAddress = new Uri(rabbitModeApiUrl);
|
|
});
|
|
else
|
|
throw new InvalidOperationException(
|
|
$"Missing API URL configuration." +
|
|
$"When ClientType is set to RabbitMQ in an isolated host, Notification:ApiUrl must be provided in the '{sectionName}' configuration section.");
|
|
break;
|
|
default:
|
|
throw new InvalidOperationException(
|
|
$"Unsupported ConsumerType '{options.ConsumerType}' in the '{sectionName}' configuration section.");
|
|
}
|
|
|
|
services.AddScoped<IEnvelopeNotificationService, EnvelopeNotificationService>();
|
|
return services;
|
|
}
|
|
}
|