Refactor: Rename OutgoingEmail to SendingEmail

This commit renames and refactors all instances of `OutgoingEmail` to `SendingEmail` across the codebase to improve terminology consistency and align with domain language.

- Renamed classes, interfaces, and records (e.g., `OutgoingEmailPublisher` → `SendingEmailPublisher`, `OutgoingEmailEvent` → `SendingEmailEvent`).
- Updated method signatures, parameters, and return types to use `SendingEmail`.
- Adjusted dependency injection registrations to reflect the new naming.
- Updated mappings in `EmailMappingProfile` to map `SendEmailCommand` to `SendingEmailEvent`.
- Refactored `SendEmailCommand` and its handler to work with `SendingEmailEvent`.
- Updated `EmailsController` to use `SendingEmailEvent` in the `SendEmail` action.
- Refactored integration tests to test `SendingEmailPublisher` and updated test data accordingly.
- Updated log messages, error handling, and comments to reflect the new terminology.
- Revised documentation and utility methods to use `SendingEmailEvent`.

This refactor ensures consistency, improves readability, and reduces ambiguity in the codebase.
This commit is contained in:
2026-08-05 13:26:21 +02:00
parent e550db8789
commit 58ad50b96b
15 changed files with 55 additions and 55 deletions

View File

@@ -33,7 +33,7 @@ public static class DependencyInjection
services.AddSingleton<IEncryptionService, DataProtectionEncryptionService>();
// --- Email Queue (RabbitMQ) ---
services.AddSingleton<OutgoingEmailConsumer>();
services.AddSingleton<SendingEmailConsumer>();
services.AddMessagingServicePublisher();
// --- RabbitMQ Configuration ---

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 : IAsyncDisposable
public sealed class SendingEmailConsumer : IAsyncDisposable
{
private readonly RabbitMqConfiguration _config;
@@ -23,9 +23,9 @@ public sealed class OutgoingEmailConsumer : IAsyncDisposable
private readonly Lazy<Task> _lazyInit;
private readonly ILogger<OutgoingEmailConsumer>? _logger;
private readonly ILogger<SendingEmailConsumer>? _logger;
public OutgoingEmailConsumer(IOptions<RabbitMqConfiguration> config, IEmailService EmailService, RabbitMqConnectionFactory CnnFactory, ILogger<OutgoingEmailConsumer>? logger = null)
public SendingEmailConsumer(IOptions<RabbitMqConfiguration> config, IEmailService EmailService, RabbitMqConnectionFactory CnnFactory, ILogger<SendingEmailConsumer>? logger = null)
{
_logger = logger;
_config = config.Value;
@@ -38,11 +38,11 @@ public sealed class OutgoingEmailConsumer : IAsyncDisposable
consumer.ReceivedAsync += async (sender, args) =>
{
OutgoingEmailEvent? oMailEvent = null;
SendingEmailEvent? oMailEvent = null;
try
{
var json = Encoding.UTF8.GetString(args.Body.ToArray());
oMailEvent = JsonSerializer.Deserialize<OutgoingEmailEvent>(json);
oMailEvent = JsonSerializer.Deserialize<SendingEmailEvent>(json);
if (oMailEvent is not null)
{
@@ -69,7 +69,7 @@ public sealed class OutgoingEmailConsumer : IAsyncDisposable
// TODO: Error Reporting Strategy
// Option 1: Separate RabbitMQ Queue (emailprofiler.errors)
// - Create EmailErrorReport entity { OutgoingEmailEventId, Exception, StackTrace, Timestamp, RetryAttempt }
// - Create EmailErrorReport entity { SendingEmailEventId, Exception, StackTrace, Timestamp, RetryAttempt }
// - Publish to error queue: await _errorQueue.EnqueueAsync(errorReport)
// - Separate worker processes error queue → Log to DB/File/External monitoring
//
@@ -111,7 +111,7 @@ public sealed class OutgoingEmailConsumer : IAsyncDisposable
public async Task InitAsync()
{
if (_lazyInit.IsValueCreated)
_logger?.LogWarning("OutgoingEmailConsumer already initialized. InitAsync() called multiple times.");
_logger?.LogWarning("SendingEmailConsumer already initialized. InitAsync() called multiple times.");
await _lazyInit.Value;
}

View File

@@ -9,7 +9,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(OutgoingEmailConsumer EmailConsumer) : BackgroundService
public class AsyncInitWorker(SendingEmailConsumer EmailConsumer) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{

View File

@@ -13,7 +13,7 @@ public static class DependencyInjection
services.AddRabbitMqConnectionFactory(configure);
// --- Email Queue (RabbitMQ) ---
services.AddSingleton<IOutgoingEmailPublisher, OutgoingEmailPublisher>();
services.AddSingleton<ISendingEmailPublisher, SendingEmailPublisher>();
return services;
}

View File

@@ -13,14 +13,14 @@ namespace DigitalData.MessagingService.Publisher;
/// Provides message persistence, scalability, and reliability.
/// Uses Lazy<T> initialization pattern to avoid blocking constructor.
/// </summary>
public sealed class OutgoingEmailPublisher : IOutgoingEmailPublisher, IAsyncDisposable
public sealed class SendingEmailPublisher : ISendingEmailPublisher, IAsyncDisposable
{
private readonly RabbitMqConfiguration _config;
private readonly ILogger<OutgoingEmailPublisher> _logger;
private readonly ILogger<SendingEmailPublisher> _logger;
private readonly RabbitMqConnectionFactory _cnnFactory;
private readonly Lazy<Task<IChannel>> _lazyChannel;
public OutgoingEmailPublisher(IOptions<RabbitMqConfiguration> config, ILogger<OutgoingEmailPublisher> logger, RabbitMqConnectionFactory cnnFactory)
public SendingEmailPublisher(IOptions<RabbitMqConfiguration> config, ILogger<SendingEmailPublisher> logger, RabbitMqConnectionFactory cnnFactory)
{
_config = config.Value;
_logger = logger;
@@ -66,9 +66,9 @@ public sealed class OutgoingEmailPublisher : IOutgoingEmailPublisher, IAsyncDisp
return channel;
}
public async Task EnqueueAsync(OutgoingEmailEvent outgoingEmailEvent, CancellationToken cancellationToken = default)
public async Task EnqueueAsync(SendingEmailEvent sendingEmailEvent, CancellationToken cancellationToken = default)
{
var json = JsonSerializer.Serialize(outgoingEmailEvent);
var json = JsonSerializer.Serialize(sendingEmailEvent);
var body = Encoding.UTF8.GetBytes(json);
var properties = new BasicProperties