Integration event is added.
This commit is contained in:
parent
fe8528d855
commit
48caa9bb2c
@ -0,0 +1,40 @@
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.EventHandling;
|
||||
|
||||
public class OrderCompletedIntegrationEventHandler : IIntegrationEventHandler<OrderCompletedIntegrationEvent>
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly ILogger<OrderCompletedIntegrationEventHandler> _logger;
|
||||
|
||||
public OrderCompletedIntegrationEventHandler(
|
||||
IMediator mediator,
|
||||
ILogger<OrderCompletedIntegrationEventHandler> logger)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_logger = logger ?? throw new System.ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event handler which confirms order is completed.
|
||||
/// </summary>
|
||||
/// <param name="event">
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public async Task Handle(OrderCompletedIntegrationEvent @event)
|
||||
{
|
||||
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
|
||||
{
|
||||
_logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
|
||||
|
||||
var command = new SetAwaitingValidationOrderStatusCommand(@event.OrderId);
|
||||
|
||||
_logger.LogInformation(
|
||||
"Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
|
||||
command.GetGenericTypeName(),
|
||||
nameof(command.OrderNumber),
|
||||
command.OrderNumber,
|
||||
command);
|
||||
|
||||
await _mediator.Send(command);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.IntegrationEvents.Events;
|
||||
|
||||
public record OrderCompletedIntegrationEvent : IntegrationEvent
|
||||
{
|
||||
public int OrderId { get; }
|
||||
|
||||
public OrderCompletedIntegrationEvent(int orderId) =>
|
||||
OrderId = orderId;
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ services.AddScoped<IRequestManager, RequestManager>();
|
||||
|
||||
// Add integration event handlers.
|
||||
services.AddTransient<IIntegrationEventHandler<GracePeriodConfirmedIntegrationEvent>, GracePeriodConfirmedIntegrationEventHandler>();
|
||||
services.AddTransient<IIntegrationEventHandler<OrderCompletedIntegrationEvent>, OrderCompletedIntegrationEventHandler>();
|
||||
services.AddTransient<IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>, OrderPaymentFailedIntegrationEventHandler>();
|
||||
services.AddTransient<IIntegrationEventHandler<OrderPaymentSucceededIntegrationEvent>, OrderPaymentSucceededIntegrationEventHandler>();
|
||||
services.AddTransient<IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>, OrderStockConfirmedIntegrationEventHandler>();
|
||||
@ -52,6 +53,7 @@ var eventBus = app.Services.GetRequiredService<IEventBus>();
|
||||
|
||||
eventBus.Subscribe<UserCheckoutAcceptedIntegrationEvent, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
|
||||
eventBus.Subscribe<GracePeriodConfirmedIntegrationEvent, IIntegrationEventHandler<GracePeriodConfirmedIntegrationEvent>>();
|
||||
eventBus.Subscribe<OrderCompletedIntegrationEvent, IIntegrationEventHandler<OrderCompletedIntegrationEvent>>();
|
||||
eventBus.Subscribe<OrderStockConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>>();
|
||||
eventBus.Subscribe<OrderStockRejectedIntegrationEvent, IIntegrationEventHandler<OrderStockRejectedIntegrationEvent>>();
|
||||
eventBus.Subscribe<OrderPaymentFailedIntegrationEvent, IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user