Refactor: Remove IOutgoingEmailConsumer interface

Simplified the codebase by removing the `IOutgoingEmailConsumer` interface and directly using the `OutgoingEmailConsumer` class.

- Removed `IOutgoingEmailConsumer` from the application.
- Updated `DependencyInjection` to register `OutgoingEmailConsumer` directly.
- Modified `OutgoingEmailConsumer` to no longer implement the removed interface.
- Updated `AsyncInitWorker` to depend directly on `OutgoingEmailConsumer`.
- Simplified initialization logic for email consumer and publisher.

These changes eliminate an unnecessary abstraction layer, making the code easier to maintain while preserving functionality.
This commit is contained in:
2026-07-27 10:04:05 +02:00
parent 1617d4ab43
commit b6470fce5a
4 changed files with 6 additions and 15 deletions

View File

@@ -32,7 +32,7 @@ public static class DependencyInjection
services.AddSingleton<IEncryptionService, DataProtectionEncryptionService>();
// --- Email Queue (RabbitMQ) ---
services.AddSingleton<IOutgoingEmailConsumer, OutgoingEmailConsumer>();
services.AddSingleton<OutgoingEmailConsumer>();
services.AddSingleton<IOutgoingEmailPublisher, OutgoingEmailPublisher>();
services.AddSingleton<RabbitMqConnectionFactory>();

View File

@@ -15,7 +15,7 @@ namespace DigitalData.MessagingService.Infrastructure.Queue;
/// Provides message persistence, scalability, and reliability.
/// Uses Lazy<T> initialization pattern to avoid blocking constructor.
/// </summary>
public sealed class OutgoingEmailConsumer(IOptions<RabbitMqConfiguration> config, ILogger<OutgoingEmailConsumer> Logger, IEmailService EmailService, RabbitMqConnectionFactory CnnFactory) : IOutgoingEmailConsumer, IAsyncDisposable
public sealed class OutgoingEmailConsumer(IOptions<RabbitMqConfiguration> config, ILogger<OutgoingEmailConsumer> Logger, IEmailService EmailService, RabbitMqConnectionFactory CnnFactory) : IAsyncDisposable
{
private readonly RabbitMqConfiguration _config = config.Value;
private IChannel? _consumeChannel = null; // Dedicated channel for consuming

View File

@@ -10,7 +10,7 @@ namespace DigitalData.MessagingService.Infrastructure.Services.Background;
/// Leverages a push-based, event-driven RabbitMQ consumer to eliminate polling overhead.
/// Email account configuration is resolved exclusively from application settings; no database access is performed.
/// </summary>
public class AsyncInitWorker(IOutgoingEmailConsumer EmailConsumer, IOutgoingEmailPublisher EmailPublisher, RabbitMqConnectionFactory CnnFactory) : BackgroundService
public class AsyncInitWorker(OutgoingEmailConsumer EmailConsumer, IOutgoingEmailPublisher EmailPublisher, RabbitMqConnectionFactory CnnFactory) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
@@ -18,10 +18,9 @@ public class AsyncInitWorker(IOutgoingEmailConsumer EmailConsumer, IOutgoingEmai
// message processing is handled asynchronously via registered event callbacks.
await CnnFactory.InitAsync(stoppingToken);
if (EmailConsumer is OutgoingEmailConsumer outgoingEmailConsumer)
await outgoingEmailConsumer.InitAsync();
await EmailConsumer.InitAsync();
if (EmailPublisher is OutgoingEmailPublisher outgoingEmailPublisher)
await outgoingEmailPublisher.InitAsync();
if (EmailPublisher is OutgoingEmailPublisher emailPublisher)
await emailPublisher.InitAsync();
}
}