mirror of
https://github.com/farcasclaudiu/PracticeCalendar.git
synced 2026-06-22 09:01:18 +03:00
refactoring and integration tests
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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)!;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user