Browse Source

provide support for cancellation tokens in command handlers

pull/1033/head
Lee Dumond 5 years ago
parent
commit
e4dc90356e
10 changed files with 13 additions and 13 deletions
  1. +1
    -1
      src/Services/Ordering/Ordering.API/Application/Commands/CancelOrderCommandHandler.cs
  2. +1
    -1
      src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs
  3. +1
    -1
      src/Services/Ordering/Ordering.API/Application/Commands/IdentifiedCommandHandler.cs
  4. +1
    -1
      src/Services/Ordering/Ordering.API/Application/Commands/SetAwaitingValidationOrderStatusCommandHandler.cs
  5. +2
    -2
      src/Services/Ordering/Ordering.API/Application/Commands/SetPaidOrderStatusCommandHandler.cs
  6. +2
    -2
      src/Services/Ordering/Ordering.API/Application/Commands/SetStockConfirmedOrderStatusCommandHandler.cs
  7. +2
    -2
      src/Services/Ordering/Ordering.API/Application/Commands/SetStockRejectedOrderStatusCommandHandler.cs
  8. +1
    -1
      src/Services/Ordering/Ordering.API/Application/Commands/ShipOrderCommandHandler.cs
  9. +1
    -1
      src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStartedEvent/ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler.cs
  10. +1
    -1
      src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs

+ 1
- 1
src/Services/Ordering/Ordering.API/Application/Commands/CancelOrderCommandHandler.cs View File

@ -33,7 +33,7 @@ namespace Ordering.API.Application.Commands
}
orderToUpdate.SetCancelledStatus();
return await _orderRepository.UnitOfWork.SaveEntitiesAsync();
return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
}
}


+ 1
- 1
src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs View File

@ -58,7 +58,7 @@
_orderRepository.Add(order);
return await _orderRepository.UnitOfWork
.SaveEntitiesAsync();
.SaveEntitiesAsync(cancellationToken);
}
}


+ 1
- 1
src/Services/Ordering/Ordering.API/Application/Commands/IdentifiedCommandHandler.cs View File

@ -96,7 +96,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands
command);
// Send the embeded business command to mediator so it runs its related CommandHandler
var result = await _mediator.Send(command);
var result = await _mediator.Send(command, cancellationToken);
_logger.LogInformation(
"----- Command result: {@Result} - {CommandName} - {IdProperty}: {CommandId} ({@Command})",


+ 1
- 1
src/Services/Ordering/Ordering.API/Application/Commands/SetAwaitingValidationOrderStatusCommandHandler.cs View File

@ -33,7 +33,7 @@ namespace Ordering.API.Application.Commands
}
orderToUpdate.SetAwaitingValidationStatus();
return await _orderRepository.UnitOfWork.SaveEntitiesAsync();
return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
}
}


+ 2
- 2
src/Services/Ordering/Ordering.API/Application/Commands/SetPaidOrderStatusCommandHandler.cs View File

@ -27,7 +27,7 @@ namespace Ordering.API.Application.Commands
public async Task<bool> Handle(SetPaidOrderStatusCommand command, CancellationToken cancellationToken)
{
// Simulate a work time for validating the payment
await Task.Delay(10000);
await Task.Delay(10000, cancellationToken);
var orderToUpdate = await _orderRepository.GetAsync(command.OrderNumber);
if(orderToUpdate == null)
@ -36,7 +36,7 @@ namespace Ordering.API.Application.Commands
}
orderToUpdate.SetPaidStatus();
return await _orderRepository.UnitOfWork.SaveEntitiesAsync();
return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
}
}


+ 2
- 2
src/Services/Ordering/Ordering.API/Application/Commands/SetStockConfirmedOrderStatusCommandHandler.cs View File

@ -27,7 +27,7 @@ namespace Ordering.API.Application.Commands
public async Task<bool> Handle(SetStockConfirmedOrderStatusCommand command, CancellationToken cancellationToken)
{
// Simulate a work time for confirming the stock
await Task.Delay(10000);
await Task.Delay(10000, cancellationToken);
var orderToUpdate = await _orderRepository.GetAsync(command.OrderNumber);
if(orderToUpdate == null)
@ -36,7 +36,7 @@ namespace Ordering.API.Application.Commands
}
orderToUpdate.SetStockConfirmedStatus();
return await _orderRepository.UnitOfWork.SaveEntitiesAsync();
return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
}
}


+ 2
- 2
src/Services/Ordering/Ordering.API/Application/Commands/SetStockRejectedOrderStatusCommandHandler.cs View File

@ -27,7 +27,7 @@ namespace Ordering.API.Application.Commands
public async Task<bool> Handle(SetStockRejectedOrderStatusCommand command, CancellationToken cancellationToken)
{
// Simulate a work time for rejecting the stock
await Task.Delay(10000);
await Task.Delay(10000, cancellationToken);
var orderToUpdate = await _orderRepository.GetAsync(command.OrderNumber);
if(orderToUpdate == null)
@ -37,7 +37,7 @@ namespace Ordering.API.Application.Commands
orderToUpdate.SetCancelledStatusWhenStockIsRejected(command.OrderStockItems);
return await _orderRepository.UnitOfWork.SaveEntitiesAsync();
return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
}
}


+ 1
- 1
src/Services/Ordering/Ordering.API/Application/Commands/ShipOrderCommandHandler.cs View File

@ -33,7 +33,7 @@ namespace Ordering.API.Application.Commands
}
orderToUpdate.SetShippedStatus();
return await _orderRepository.UnitOfWork.SaveEntitiesAsync();
return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
}
}


+ 1
- 1
src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStartedEvent/ValidateOrAddBuyerAggregateWhenOrderStartedDomainEventHandler.cs View File

@ -56,7 +56,7 @@ namespace Ordering.API.Application.DomainEventHandlers.OrderStartedEvent
_buyerRepository.Add(buyer);
await _buyerRepository.UnitOfWork
.SaveEntitiesAsync();
.SaveEntitiesAsync(cancellationToken);
var orderStatusChangedTosubmittedIntegrationEvent = new OrderStatusChangedToSubmittedIntegrationEvent(orderStartedEvent.Order.Id, orderStartedEvent.Order.OrderStatus.Name, buyer.Name);
await _orderingIntegrationEventService.AddAndSaveEventAsync(orderStatusChangedTosubmittedIntegrationEvent);


+ 1
- 1
src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs View File

@ -64,7 +64,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
// After executing this line all the changes (from the Command Handler and Domain Event Handlers)
// performed through the DbContext will be committed
var result = await base.SaveChangesAsync();
var result = await base.SaveChangesAsync(cancellationToken);
return true;
}


Loading…
Cancel
Save