mirror of
https://github.com/farcasclaudiu/PracticeCalendar.git
synced 2026-06-22 11:01:27 +03:00
31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
using MediatR;
|
|
using Microsoft.Extensions.Logging;
|
|
using PracticeCalendar.Domain.Common;
|
|
using PracticeCalendar.Domain.Common.Interfaces;
|
|
|
|
namespace PracticeCalendar.Infrastructure.Services
|
|
{
|
|
public class DomainEventService : IDomainEventService
|
|
{
|
|
private readonly ILogger<DomainEventService> logger;
|
|
private readonly IPublisher mediator;
|
|
|
|
public DomainEventService(ILogger<DomainEventService> logger, IPublisher mediator)
|
|
{
|
|
this.logger = logger;
|
|
this.mediator = mediator;
|
|
}
|
|
public async Task Publish(DomainEventBase domainEvent)
|
|
{
|
|
logger.LogInformation("Publishing domain event. Event - {event}", domainEvent.GetType().Name);
|
|
await mediator.Publish(GetNotificationCorrespondingToDomainEvent(domainEvent));
|
|
}
|
|
|
|
private INotification GetNotificationCorrespondingToDomainEvent(DomainEventBase domainEvent)
|
|
{
|
|
return (INotification)Activator.CreateInstance(
|
|
typeof(DomainEventNotification<>).MakeGenericType(domainEvent.GetType()), domainEvent)!;
|
|
}
|
|
}
|
|
}
|