Merge pull request #1033 from LeeDumond/enhance/cancellation-token-support

provide support for cancellation tokens in command handlers
This commit is contained in:
Miguel Veloso 2019-05-08 11:16:07 +01:00 committed by GitHub
commit 7b300ec912
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 13 additions and 13 deletions

View File

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

View File

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

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})",

View File

@ -33,7 +33,7 @@ namespace Ordering.API.Application.Commands
}
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)
{
// 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);
}
}

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);
}
}

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);
}
}

View File

@ -33,7 +33,7 @@ namespace Ordering.API.Application.Commands
}
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);
await _buyerRepository.UnitOfWork
.SaveEntitiesAsync();
.SaveEntitiesAsync(cancellationToken);
var orderStatusChangedTosubmittedIntegrationEvent = new OrderStatusChangedToSubmittedIntegrationEvent(orderStartedEvent.Order.Id, orderStartedEvent.Order.OrderStatus.Name, buyer.Name);
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)
// performed through the DbContext will be committed
var result = await base.SaveChangesAsync();
var result = await base.SaveChangesAsync(cancellationToken);
return true;
}