Ordering. Fixed async/await misuses
This commit is contained in:
parent
05e754662e
commit
ded950ca36
@ -22,6 +22,7 @@ namespace Ordering.API.Application.Commands
|
||||
/// customer executes cancel order from app
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> Handle(CancelOrderCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
@ -32,7 +33,7 @@ namespace Ordering.API.Application.Commands
|
||||
}
|
||||
|
||||
orderToUpdate.SetCancelledStatus();
|
||||
return await _orderRepository.UnitOfWork.SaveEntitiesAsync();
|
||||
return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +47,7 @@ namespace Ordering.API.Application.Commands
|
||||
|
||||
protected override bool CreateResultForDuplicateRequest()
|
||||
{
|
||||
return true; // Ignore duplicate requests for processing order.
|
||||
return true; // Ignore duplicate requests for processing order.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands
|
||||
/// just enqueues the original inner command.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
public async Task<R> Handle(IdentifiedCommand<T, R> message, CancellationToken cancellationToken)
|
||||
{
|
||||
@ -48,16 +49,16 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands
|
||||
else
|
||||
{
|
||||
await _requestManager.CreateRequestForCommandAsync<T>(message.Id);
|
||||
try
|
||||
{
|
||||
// Send the embeded business command to mediator so it runs its related CommandHandler
|
||||
var result = await _mediator.Send(message.Command);
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return default(R);
|
||||
}
|
||||
try
|
||||
{
|
||||
// Send the embeded business command to mediator so it runs its related CommandHandler
|
||||
var result = await _mediator.Send(message.Command, cancellationToken);
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return default(R);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ namespace Ordering.API.Application.Commands
|
||||
/// administrator executes ship order from app
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> Handle(ShipOrderCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
@ -32,7 +33,7 @@ namespace Ordering.API.Application.Commands
|
||||
}
|
||||
|
||||
orderToUpdate.SetShippedStatus();
|
||||
return await _orderRepository.UnitOfWork.SaveEntitiesAsync();
|
||||
return await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +47,7 @@ namespace Ordering.API.Application.Commands
|
||||
|
||||
protected override bool CreateResultForDuplicateRequest()
|
||||
{
|
||||
return true; // Ignore duplicate requests for processing order.
|
||||
return true; // Ignore duplicate requests for processing order.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
||||
{
|
||||
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
|
||||
|
||||
|
||||
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)
|
||||
// performed throught the DbContext will be commited
|
||||
var result = await base.SaveChangesAsync();
|
||||
var result = await base.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -70,7 +69,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
||||
var optionsBuilder = new DbContextOptionsBuilder<OrderingContext>()
|
||||
.UseSqlServer("Server=.;Initial Catalog=Microsoft.eShopOnContainers.Services.OrderingDb;Integrated Security=true");
|
||||
|
||||
return new OrderingContext(optionsBuilder.Options,new NoMediator());
|
||||
return new OrderingContext(optionsBuilder.Options, new NoMediator());
|
||||
}
|
||||
|
||||
class NoMediator : IMediator
|
||||
|
Loading…
x
Reference in New Issue
Block a user