Sep 11 2023
public class AccidentNotificaiton : INotification
{
public AccisdentNotification(string location)
{
Location = location;
}
public string Location { get; }
}
public class PoliceSubscriber : INotificationHandler<AccidentNotification>
{
public async Task Handle(AccidentNotification notification,
CancellationToken cancellationToken)
{
Console.WriteLine();
Console.WriteLine($"The police service received a notificaiton about the accident");
Console.WriteLine($"Police were dispatched to the location: {notification.Location}");
}
}
[HttpPost("notify-accident")]
public async Task<IActionResult> NotifyAboutAccident(AccidentNotification notification)
{
await _mediator.Publish(notification);
return Ok();
}
builder.Services
.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
Join 13,250+ subscribers to improve your .NET Knowledge.
Go-to resource for understanding the core concepts of design patterns without the overwhelming complexity. In this concise and affordable ebook, I've distilled the essence of design patterns into an easy-to-digest format. It is a Beginner level. Check out it here.
Every Monday morning, I share 1 actionable tip on C#, .NET & Arcitecture topic, that you can use right away.
Subscribe to the TheCodeMan.net and be among the 13,250+ subscribers gaining practical tips and resources to enhance your .NET expertise.