mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-14 17:54:42 +00:00
41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using Features.Emails.Services;
|
|
using Features.Users.Notifications;
|
|
using MediatR;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Features.Emails.Notifications;
|
|
|
|
/// <summary>
|
|
/// Handles <see cref="UserRegisteredNotification" />, the cross-slice notification published by
|
|
/// Features.Users after a new user registers, by sending the registration confirmation email.
|
|
/// </summary>
|
|
public class UserRegisteredNotificationHandler(
|
|
IEmailDispatcher emailDispatcher,
|
|
ILogger<UserRegisteredNotificationHandler> logger
|
|
) : INotificationHandler<UserRegisteredNotification>
|
|
{
|
|
/// <remarks>
|
|
/// Delivery failures are logged and swallowed rather than rethrown, so that a broken mail server
|
|
/// never fails the registration that already succeeded.
|
|
/// </remarks>
|
|
public async Task Handle(UserRegisteredNotification notification, CancellationToken cancellationToken)
|
|
{
|
|
try
|
|
{
|
|
await emailDispatcher.SendRegistrationEmailAsync(
|
|
notification.FirstName,
|
|
notification.Email,
|
|
notification.ConfirmationToken
|
|
);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.LogError(
|
|
ex,
|
|
"Failed to send registration confirmation email to user {UserId}",
|
|
notification.UserId
|
|
);
|
|
}
|
|
}
|
|
}
|