This repository was archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Expand file tree
/
Copy pathOrderCompletedDomainEventHandler.cs
More file actions
35 lines (30 loc) · 1.83 KB
/
OrderCompletedDomainEventHandler.cs
File metadata and controls
35 lines (30 loc) · 1.83 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
using Ordering.Domain.Events;
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.DomainEventHandlers
{
public class OrderCompletedDomainEventHandler : INotificationHandler<OrderCompletedDomainEvent>
{
private readonly IOrderRepository _orderRepository;
private readonly IBuyerRepository _buyerRepository;
private readonly ILogger _logger;
private readonly IOrderingIntegrationEventService _orderingIntegrationEventService;
public OrderCompletedDomainEventHandler(
IOrderRepository orderRepository,
ILogger<OrderCompletedDomainEventHandler> logger,
IBuyerRepository buyerRepository,
IOrderingIntegrationEventService orderingIntegrationEventService)
{
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_buyerRepository = buyerRepository ?? throw new ArgumentNullException(nameof(buyerRepository));
_orderingIntegrationEventService = orderingIntegrationEventService ?? throw new ArgumentNullException(nameof(orderingIntegrationEventService));
}
public async Task Handle(OrderCompletedDomainEvent domainEvent, CancellationToken cancellationToken)
{
OrderingApiTrace.LogOrderStatusUpdated(_logger, domainEvent.Order.Id, nameof(OrderStatus.Completed), OrderStatus.Completed.Id);
var order = await _orderRepository.GetAsync(domainEvent.Order.Id);
var buyer = await _buyerRepository.FindByIdAsync(order.GetBuyerId.Value.ToString());
var integrationEvent = new OrderCompletedIntegrationEvent(order.Id);
await _orderingIntegrationEventService.AddAndSaveEventAsync(integrationEvent);
}
}
}