-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUserCreatedNotification.cs
More file actions
51 lines (45 loc) · 1.75 KB
/
Copy pathUserCreatedNotification.cs
File metadata and controls
51 lines (45 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using Bas24.CommandQuery.Notifications;
namespace Sample;
public interface IEmailService
{
Task SendWelcomeEmailAsync(Guid notificationUserId, string notificationName);
}
public class EmailService(ILogger<EmailService> logger) : IEmailService
{
public Task SendWelcomeEmailAsync(Guid notificationUserId, string notificationName)
{
logger.LogDebug("EmailService: Sending welcome email to {NotificationName} with ID {NotificationUserId}", notificationName, notificationUserId);
return Task.CompletedTask;
}
}
public interface ISmsService
{
Task SendWelcomeSmsAsync(Guid notificationUserId, string notificationName);
}
public class SmsService(ILogger<SmsService> logger) : ISmsService
{
public Task SendWelcomeSmsAsync(Guid notificationUserId, string notificationName)
{
logger.LogDebug("SmsService: Sending welcome SMS to {NotificationName} with ID {NotificationUserId}", notificationName, notificationUserId);
return Task.CompletedTask;
}
}
public class UserCreatedNotification : INotification
{
public Guid UserId { get; set; }
public string Name { get; set; } = string.Empty;
}
public class EmailNotificationHandler(IEmailService emailService) : INotificationHandler<UserCreatedNotification>
{
public async Task Handle(UserCreatedNotification notification, CancellationToken cancellationToken)
{
await emailService.SendWelcomeEmailAsync(notification.UserId, notification.Name);
}
}
public class SmsNotificationHandler(ISmsService smsService) : INotificationHandler<UserCreatedNotification>
{
public async Task Handle(UserCreatedNotification notification, CancellationToken cancellationToken)
{
await smsService.SendWelcomeSmsAsync(notification.UserId, notification.Name);
}
}