-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathTripCreatedDomainEventHandlerAsync.cs
More file actions
36 lines (31 loc) · 1.37 KB
/
TripCreatedDomainEventHandlerAsync.cs
File metadata and controls
36 lines (31 loc) · 1.37 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
using System;
using System.Threading.Tasks;
using AutoMapper;
using Duber.Domain.Trip.Events;
using Duber.Infrastructure.EventBus.Abstractions;
using Duber.Trip.API.Application.IntegrationEvents;
using OpenCqrs.Events;
using Microsoft.Extensions.Logging;
namespace Duber.Trip.API.Application.DomainEventHandlers
{
public class TripCreatedDomainEventHandlerAsync : IEventHandlerAsync<TripCreatedDomainEvent>
{
private readonly IEventBus _eventBus;
private readonly IMapper _mapper;
private readonly ILogger<TripCreatedDomainEventHandlerAsync> _logger;
public TripCreatedDomainEventHandlerAsync(IEventBus eventBus, IMapper mapper, ILogger<TripCreatedDomainEventHandlerAsync> logger)
{
_eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
_logger = logger;
}
public async Task HandleAsync(TripCreatedDomainEvent @event)
{
_logger.LogInformation($"Trip {@event.AggregateRootId} has been created.");
var integrationEvent = _mapper.Map<TripCreatedIntegrationEvent>(@event);
// to update the query side (materialized view)
_eventBus.Publish(integrationEvent); // TODO: make an async Publish method.
await Task.CompletedTask;
}
}
}