Refactor EmailSender to use new Email abstraction
Introduced a new `Email` record to simplify the representation of outgoing email messages. Updated the `EmailSender.Send` method to accept `Email` instead of `OutgoingEmailEvent`, with a `ToEvent()` method handling the conversion internally. Refactored test cases to use the `Email` record, removing redundant properties (`Id` and `QueuedAt`) that are now auto-generated. Updated XML documentation to reflect these changes. Adjusted namespaces and added necessary `using` directives for proper referencing. These changes improve code readability, maintainability, and centralize the mapping logic for outgoing email events.
This commit is contained in:
@@ -106,24 +106,25 @@ public static class EmailSender
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enqueues the specified email event to the RabbitMQ messaging pipeline.
|
||||
/// Enqueues the specified email to the RabbitMQ messaging pipeline.
|
||||
/// </summary>
|
||||
/// <param name="email">The outgoing email event to enqueue.</param>
|
||||
/// <param name="email">The outgoing email data to enqueue.</param>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// Thrown when <see cref="ConnectRabbitMq(Action{RabbitMqConfiguration}, OnReconnect)"/> has not been called prior to sending.
|
||||
/// </exception>
|
||||
/// <remarks>
|
||||
/// This method resolves <see cref="IOutgoingEmailPublisher"/> from the internal
|
||||
/// This method maps <see cref="Email"/> to <see cref="OutgoingEmailEvent"/>,
|
||||
/// then resolves <see cref="IOutgoingEmailPublisher"/> from the internal
|
||||
/// service provider and calls <c>EnqueueAsync</c> in a fire-and-forget manner.
|
||||
/// Ensure that any unhandled exceptions from the async operation are handled
|
||||
/// at the publisher level.
|
||||
/// </remarks>
|
||||
public static void Send(OutgoingEmailEvent email)
|
||||
public static void Send(Email email)
|
||||
{
|
||||
if(!IsConnected)
|
||||
throw new InvalidOperationException("Messaging service is not connected. Call ConnectRabbitMq first.");
|
||||
|
||||
var publisher = LazyProvider.Value.GetRequiredService<IOutgoingEmailPublisher>();
|
||||
publisher.EnqueueAsync(email);
|
||||
publisher.EnqueueAsync(email.ToEvent());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user