Files
DigitalData.MessagingService/src/DigitalData.EmailProfiler.Infrastructure/DependencyInjection.cs
TekH 3cba69ec42 Refactor email queue worker and interface cleanup
Removed `InitAsync` from `IOutgoingEmailQueue` to decouple RabbitMQ initialization from the interface. Replaced `AsyncIniteWorker` with the correctly named `AsyncInitWorker` in `DependencyInjection.cs` and introduced a new, improved implementation of `AsyncInitWorker`.

The new `AsyncInitWorker` class initializes the outgoing email queue consumer using an event-driven RabbitMQ approach, with enhanced logging and error handling. Removed the outdated `AsyncIniteWorker` class to streamline the codebase.

These changes improve code clarity, maintainability, and correctness.
2026-07-24 12:30:36 +02:00

52 lines
2.0 KiB
C#

using DigitalData.EmailProfiler.Application.Common.Interfaces;
using DigitalData.EmailProfiler.Infrastructure.Messaging;
using DigitalData.EmailProfiler.Infrastructure.Queue;
using DigitalData.EmailProfiler.Infrastructure.Services;
using DigitalData.EmailProfiler.Infrastructure.Services.Background;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace DigitalData.EmailProfiler.Infrastructure;
/// <summary>
/// Dependency injection configuration for Infrastructure layer
/// </summary>
public static class DependencyInjection
{
/// <summary>
/// Adds Infrastructure layer services to the DI container
/// </summary>
public static IServiceCollection AddInfrastructure(
this IServiceCollection services,
IConfiguration configuration)
{
// --- External Services ---
// Email Service (using Limilabs Mail.dll - Singleton for use in EmailSenderWorker)
services.AddSingleton<IEmailService, LimilabsEmailService>();
// PDF Processing Service (using DevExpress.Pdf)
services.AddScoped<IPdfProcessingService, DevExpressPdfProcessingService>();
// Encryption Service (using Data Protection API - Singleton, thread-safe)
services.AddSingleton<IEncryptionService, DataProtectionEncryptionService>();
// --- Email Queue (RabbitMQ) ---
services.AddSingleton<IOutgoingEmailQueue, OutgoingEmailQueue>();
// --- RabbitMQ Configuration ---
services.Configure<RabbitMqConfiguration>(
configuration.GetSection(RabbitMqConfiguration.SectionName));
// --- Data Protection (for encryption) ---
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(@"C:\ProgramData\EmailService\Keys"))
.SetApplicationName("EmailProfiler");
// Register Background Workers
services.AddHostedService<AsyncInitWorker>();
return services;
}
}