diff --git a/src/Services/Ordering/Ordering.API/Application/Behaviors/LoggingBehavior.cs b/src/Services/Ordering/Ordering.API/Application/Behaviors/LoggingBehavior.cs index c2e04abe8..2708db8a9 100644 --- a/src/Services/Ordering/Ordering.API/Application/Behaviors/LoggingBehavior.cs +++ b/src/Services/Ordering/Ordering.API/Application/Behaviors/LoggingBehavior.cs @@ -1,8 +1,6 @@ using MediatR; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace Ordering.API.Infrastructure.Behaviors @@ -12,7 +10,7 @@ namespace Ordering.API.Infrastructure.Behaviors private readonly ILogger> _logger; public LoggingBehavior(ILogger> logger) => _logger = logger; - public async Task Handle(TRequest request, RequestHandlerDelegate next) + public async Task Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate next) { _logger.LogInformation($"Handling {typeof(TRequest).Name}"); var response = await next(); diff --git a/src/Services/Ordering/Ordering.API/Application/Behaviors/ValidatorBehavior.cs b/src/Services/Ordering/Ordering.API/Application/Behaviors/ValidatorBehavior.cs index f8f582858..de0a2ba4b 100644 --- a/src/Services/Ordering/Ordering.API/Application/Behaviors/ValidatorBehavior.cs +++ b/src/Services/Ordering/Ordering.API/Application/Behaviors/ValidatorBehavior.cs @@ -1,10 +1,9 @@ using FluentValidation; using MediatR; -using Microsoft.Extensions.Logging; using Ordering.Domain.Exceptions; using System; -using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace Ordering.API.Infrastructure.Behaviors @@ -14,7 +13,7 @@ namespace Ordering.API.Infrastructure.Behaviors private readonly IValidator[] _validators; public ValidatorBehavior(IValidator[] validators) => _validators = validators; - public async Task Handle(TRequest request, RequestHandlerDelegate next) + public async Task Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate next) { var failures = _validators .Select(v => v.Validate(request)) diff --git a/src/Services/Ordering/Ordering.API/Application/Commands/CancelOrderCommandHandler.cs b/src/Services/Ordering/Ordering.API/Application/Commands/CancelOrderCommandHandler.cs index a16acb0f3..a4c4facb8 100644 --- a/src/Services/Ordering/Ordering.API/Application/Commands/CancelOrderCommandHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/Commands/CancelOrderCommandHandler.cs @@ -2,15 +2,13 @@ using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency; -using System; -using System.Collections.Generic; -using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace Ordering.API.Application.Commands { // Regular CommandHandler - public class CancelOrderCommandHandler : IAsyncRequestHandler + public class CancelOrderCommandHandler : IRequestHandler { private readonly IOrderRepository _orderRepository; @@ -25,7 +23,7 @@ namespace Ordering.API.Application.Commands /// /// /// - public async Task Handle(CancelOrderCommand command) + public async Task Handle(CancelOrderCommand command, CancellationToken cancellationToken) { var orderToUpdate = await _orderRepository.GetAsync(command.OrderNumber); if(orderToUpdate == null) diff --git a/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs b/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs index 845caf010..c63f262fa 100644 --- a/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs @@ -5,11 +5,12 @@ using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services; using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency; using System; + using System.Threading; using System.Threading.Tasks; // Regular CommandHandler public class CreateOrderCommandHandler - : IAsyncRequestHandler + : IRequestHandler { private readonly IOrderRepository _orderRepository; private readonly IIdentityService _identityService; @@ -23,7 +24,7 @@ _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); } - public async Task Handle(CreateOrderCommand message) + public async Task Handle(CreateOrderCommand message, CancellationToken cancellationToken) { // Add/Update the Buyer AggregateRoot // DDD patterns comment: Add child entities and value-objects through the Order Aggregate-Root diff --git a/src/Services/Ordering/Ordering.API/Application/Commands/IdentifiedCommandHandler.cs b/src/Services/Ordering/Ordering.API/Application/Commands/IdentifiedCommandHandler.cs index 507595236..1f0b3ddca 100644 --- a/src/Services/Ordering/Ordering.API/Application/Commands/IdentifiedCommandHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/Commands/IdentifiedCommandHandler.cs @@ -1,5 +1,6 @@ using MediatR; using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency; +using System.Threading; using System.Threading.Tasks; namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands @@ -10,7 +11,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands /// /// Type of the command handler that performs the operation if request is not duplicated /// Return value of the inner command handler - public class IdentifiedCommandHandler : IAsyncRequestHandler, R> + public class IdentifiedCommandHandler : IRequestHandler, R> where T : IRequest { private readonly IMediator _mediator; @@ -37,7 +38,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands /// /// IdentifiedCommand which contains both original command & request ID /// Return value of inner command or default value if request same ID was found - public async Task Handle(IdentifiedCommand message) + public async Task Handle(IdentifiedCommand message, CancellationToken cancellationToken) { var alreadyExists = await _requestManager.ExistAsync(message.Id); if (alreadyExists) @@ -55,6 +56,4 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands } } } - - -} +} \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/Commands/ShipOrderCommandHandler.cs b/src/Services/Ordering/Ordering.API/Application/Commands/ShipOrderCommandHandler.cs index 7755dae32..b4a6ac26d 100644 --- a/src/Services/Ordering/Ordering.API/Application/Commands/ShipOrderCommandHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/Commands/ShipOrderCommandHandler.cs @@ -2,12 +2,13 @@ using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency; +using System.Threading; using System.Threading.Tasks; namespace Ordering.API.Application.Commands { // Regular CommandHandler - public class ShipOrderCommandHandler : IAsyncRequestHandler + public class ShipOrderCommandHandler : IRequestHandler { private readonly IOrderRepository _orderRepository; @@ -22,7 +23,7 @@ namespace Ordering.API.Application.Commands /// /// /// - public async Task Handle(ShipOrderCommand command) + public async Task Handle(ShipOrderCommand command, CancellationToken cancellationToken) { var orderToUpdate = await _orderRepository.GetAsync(command.OrderNumber); if(orderToUpdate == null) diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/BuyerAndPaymentMethodVerified/UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/BuyerAndPaymentMethodVerified/UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler.cs index 35e14dd68..d738c07ee 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/BuyerAndPaymentMethodVerified/UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/BuyerAndPaymentMethodVerified/UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler.cs @@ -1,16 +1,15 @@ using MediatR; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; using Microsoft.Extensions.Logging; -using Ordering.API.Application.IntegrationEvents; -using Ordering.API.Application.IntegrationEvents.Events; using Ordering.Domain.Events; using System; +using System.Threading; using System.Threading.Tasks; namespace Ordering.API.Application.DomainEventHandlers.BuyerAndPaymentMethodVerified { public class UpdateOrderWhenBuyerAndPaymentMethodVerifiedDomainEventHandler - : IAsyncNotificationHandler + : INotificationHandler { private readonly IOrderRepository _orderRepository; private readonly ILoggerFactory _logger; @@ -25,7 +24,7 @@ namespace Ordering.API.Application.DomainEventHandlers.BuyerAndPaymentMethodVeri // Domain Logic comment: // When the Buyer and Buyer's payment method have been created or verified that they existed, // then we can update the original Order with the BuyerId and PaymentId (foreign keys) - public async Task Handle(BuyerAndPaymentMethodVerifiedDomainEvent buyerPaymentMethodVerifiedEvent) + public async Task Handle(BuyerAndPaymentMethodVerifiedDomainEvent buyerPaymentMethodVerifiedEvent, CancellationToken cancellationToken) { var orderToUpdate = await _orderRepository.GetAsync(buyerPaymentMethodVerifiedEvent.OrderId); orderToUpdate.SetBuyerId(buyerPaymentMethodVerifiedEvent.Buyer.Id); diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs index 3c0168656..a02d07232 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs @@ -9,9 +9,10 @@ using Ordering.API.Application.IntegrationEvents; using System.Linq; using Ordering.API.Application.IntegrationEvents.Events; + using System.Threading; public class OrderStatusChangedToAwaitingValidationDomainEventHandler - : IAsyncNotificationHandler + : INotificationHandler { private readonly IOrderRepository _orderRepository; private readonly ILoggerFactory _logger; @@ -26,11 +27,11 @@ _orderingIntegrationEventService = orderingIntegrationEventService; } - public async Task Handle(OrderStatusChangedToAwaitingValidationDomainEvent orderStatusChangedToAwaitingValidationDomainEvent) + public async Task Handle(OrderStatusChangedToAwaitingValidationDomainEvent orderStatusChangedToAwaitingValidationDomainEvent, CancellationToken cancellationToken) { _logger.CreateLogger(nameof(OrderStatusChangedToAwaitingValidationDomainEvent)) - .LogTrace($"Order with Id: {orderStatusChangedToAwaitingValidationDomainEvent.OrderId} has been successfully updated with " + - $"a status order id: {OrderStatus.AwaitingValidation.Id}"); + .LogTrace($"Order with Id: {orderStatusChangedToAwaitingValidationDomainEvent.OrderId} has been successfully updated with " + + $"a status order id: {OrderStatus.AwaitingValidation.Id}"); var orderStockList = orderStatusChangedToAwaitingValidationDomainEvent.OrderItems .Select(orderItem => new OrderStockItem(orderItem.ProductId, orderItem.GetUnits())); diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs index 60f56c2e2..071cd90fc 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs @@ -9,9 +9,10 @@ using Ordering.API.Application.IntegrationEvents; using System.Linq; using Ordering.API.Application.IntegrationEvents.Events; + using System.Threading; public class OrderStatusChangedToPaidDomainEventHandler - : IAsyncNotificationHandler + : INotificationHandler { private readonly IOrderRepository _orderRepository; private readonly ILoggerFactory _logger; @@ -26,11 +27,11 @@ _orderingIntegrationEventService = orderingIntegrationEventService; } - public async Task Handle(OrderStatusChangedToPaidDomainEvent orderStatusChangedToPaidDomainEvent) + public async Task Handle(OrderStatusChangedToPaidDomainEvent orderStatusChangedToPaidDomainEvent, CancellationToken cancellationToken) { _logger.CreateLogger(nameof(OrderStatusChangedToPaidDomainEventHandler)) - .LogTrace($"Order with Id: {orderStatusChangedToPaidDomainEvent.OrderId} has been successfully updated with " + - $"a status order id: {OrderStatus.Paid.Id}"); + .LogTrace($"Order with Id: {orderStatusChangedToPaidDomainEvent.OrderId} has been successfully updated with " + + $"a status order id: {OrderStatus.Paid.Id}"); var orderStockList = orderStatusChangedToPaidDomainEvent.OrderItems .Select(orderItem => new OrderStockItem(orderItem.ProductId, orderItem.GetUnits())); diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStartedEvent/ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStartedEvent/ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler.cs index 7f5ee61a4..d222c574c 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStartedEvent/ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStartedEvent/ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler.cs @@ -4,12 +4,13 @@ using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.Buyer using Microsoft.Extensions.Logging; using Ordering.Domain.Events; using System; +using System.Threading; using System.Threading.Tasks; namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent { public class ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler - : IAsyncNotificationHandler + : INotificationHandler { private readonly ILoggerFactory _logger; private readonly IBuyerRepository _buyerRepository; @@ -22,7 +23,7 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } - public async Task Handle(OrderStartedDomainEvent orderStartedEvent) + public async Task Handle(OrderStartedDomainEvent orderStartedEvent, CancellationToken cancellationToken) { var cardTypeId = (orderStartedEvent.CardTypeId != 0) ? orderStartedEvent.CardTypeId : 1; var buyer = await _buyerRepository.FindAsync(orderStartedEvent.UserId); diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs index 7ead82c4d..3b24e43e6 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs @@ -8,9 +8,10 @@ using System.Threading.Tasks; using Ordering.API.Application.IntegrationEvents; using Ordering.API.Application.IntegrationEvents.Events; + using System.Threading; public class OrderStatusChangedToStockConfirmedDomainEventHandler - : IAsyncNotificationHandler + : INotificationHandler { private readonly IOrderRepository _orderRepository; private readonly ILoggerFactory _logger; @@ -25,7 +26,7 @@ _orderingIntegrationEventService = orderingIntegrationEventService; } - public async Task Handle(OrderStatusChangedToStockConfirmedDomainEvent orderStatusChangedToStockConfirmedDomainEvent) + public async Task Handle(OrderStatusChangedToStockConfirmedDomainEvent orderStatusChangedToStockConfirmedDomainEvent, CancellationToken cancellationToken) { _logger.CreateLogger(nameof(OrderStatusChangedToStockConfirmedDomainEventHandler)) .LogTrace($"Order with Id: {orderStatusChangedToStockConfirmedDomainEvent.OrderId} has been successfully updated with " + diff --git a/src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/MediatorModule.cs b/src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/MediatorModule.cs index d54be0a45..83c2b1ba2 100644 --- a/src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/MediatorModule.cs +++ b/src/Services/Ordering/Ordering.API/Infrastructure/AutofacModules/MediatorModule.cs @@ -21,11 +21,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Autof // Register all the Command classes (they implement IAsyncRequestHandler) in assembly holding the Commands builder.RegisterAssemblyTypes(typeof(CreateOrderCommand).GetTypeInfo().Assembly) - .AsClosedTypesOf(typeof(IAsyncRequestHandler<,>)); + .AsClosedTypesOf(typeof(IRequestHandler<,>)); // Register the DomainEventHandler classes (they implement IAsyncNotificationHandler<>) in assembly holding the Domain Events builder.RegisterAssemblyTypes(typeof(ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler).GetTypeInfo().Assembly) - .AsClosedTypesOf(typeof(IAsyncNotificationHandler<>)); + .AsClosedTypesOf(typeof(INotificationHandler<>)); // Register the Command's Validators (Validators based on FluentValidation library) builder diff --git a/src/Services/Ordering/Ordering.API/Ordering.API.csproj b/src/Services/Ordering/Ordering.API/Ordering.API.csproj index a9f1a084d..7ce3ecb0c 100644 --- a/src/Services/Ordering/Ordering.API/Ordering.API.csproj +++ b/src/Services/Ordering/Ordering.API/Ordering.API.csproj @@ -31,14 +31,14 @@ - + - + diff --git a/src/Services/Ordering/Ordering.Domain/Ordering.Domain.csproj b/src/Services/Ordering/Ordering.Domain/Ordering.Domain.csproj index e8f232b76..1ccd1143f 100644 --- a/src/Services/Ordering/Ordering.Domain/Ordering.Domain.csproj +++ b/src/Services/Ordering/Ordering.Domain/Ordering.Domain.csproj @@ -5,8 +5,8 @@ - - + +