refactoring and integration tests

This commit is contained in:
2022-10-10 04:02:46 +03:00
parent 28a6981001
commit ec54d2c255
15 changed files with 172 additions and 7 deletions
@@ -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)!;
}
}
}