provide support for cancellation tokens in command handlers

This commit is contained in:
Lee Dumond 2019-05-06 14:57:44 -05:00
parent c6ad3f2e14
commit e4dc90356e
10 changed files with 13 additions and 13 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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) // After executing this line all the changes (from the Command Handler and Domain Event Handlers)
// performed through the DbContext will be committed // performed through the DbContext will be committed
var result = await base.SaveChangesAsync(); var result = await base.SaveChangesAsync(cancellationToken);
return true; return true;
} }