Ordering. Fixed async/await misuses

This commit is contained in:
Marusyk 2018-03-29 17:31:55 +03:00
parent 05e754662e
commit ded950ca36
4 changed files with 19 additions and 17 deletions

View File

@ -22,6 +22,7 @@ namespace Ordering.API.Application.Commands
/// customer executes cancel order from app /// customer executes cancel order from app
/// </summary> /// </summary>
/// <param name="command"></param> /// <param name="command"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
public async Task<bool> Handle(CancelOrderCommand command, CancellationToken cancellationToken) public async Task<bool> Handle(CancelOrderCommand command, CancellationToken cancellationToken)
{ {
@ -32,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

@ -37,6 +37,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands
/// just enqueues the original inner command. /// just enqueues the original inner command.
/// </summary> /// </summary>
/// <param name="message">IdentifiedCommand which contains both original command & request ID</param> /// <param name="message">IdentifiedCommand which contains both original command & request ID</param>
/// <param name="cancellationToken"></param>
/// <returns>Return value of inner command or default value if request same ID was found</returns> /// <returns>Return value of inner command or default value if request same ID was found</returns>
public async Task<R> Handle(IdentifiedCommand<T, R> message, CancellationToken cancellationToken) public async Task<R> Handle(IdentifiedCommand<T, R> message, CancellationToken cancellationToken)
{ {
@ -51,7 +52,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands
try try
{ {
// 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(message.Command); var result = await _mediator.Send(message.Command, cancellationToken);
return result; return result;
} }
catch catch

View File

@ -22,6 +22,7 @@ namespace Ordering.API.Application.Commands
/// administrator executes ship order from app /// administrator executes ship order from app
/// </summary> /// </summary>
/// <param name="command"></param> /// <param name="command"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
public async Task<bool> Handle(ShipOrderCommand command, CancellationToken cancellationToken) public async Task<bool> Handle(ShipOrderCommand command, CancellationToken cancellationToken)
{ {
@ -32,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

@ -30,7 +30,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
{ {
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
System.Diagnostics.Debug.WriteLine("OrderingContext::ctor ->" + this.GetHashCode()); System.Diagnostics.Debug.WriteLine("OrderingContext::ctor ->" + this.GetHashCode());
} }
@ -57,7 +56,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 throught the DbContext will be commited // performed throught the DbContext will be commited
var result = await base.SaveChangesAsync(); var result = await base.SaveChangesAsync(cancellationToken);
return true; return true;
} }