Browse Source

Ordering. Fixed async/await misuses

pull/568/head
Marusyk 6 years ago
parent
commit
ded950ca36
4 changed files with 19 additions and 17 deletions
  1. +3
    -2
      src/Services/Ordering/Ordering.API/Application/Commands/CancelOrderCommandHandler.cs
  2. +11
    -10
      src/Services/Ordering/Ordering.API/Application/Commands/IdentifiedCommandHandler.cs
  3. +3
    -2
      src/Services/Ordering/Ordering.API/Application/Commands/ShipOrderCommandHandler.cs
  4. +2
    -3
      src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs

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

@ -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.
}
}
}

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

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

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

@ -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.
}
}
}

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

@ -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…
Cancel
Save