|
|
@ -1,5 +1,6 @@ |
|
|
|
using MediatR; |
|
|
|
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands |
|
|
@ -10,7 +11,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands |
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T">Type of the command handler that performs the operation if request is not duplicated</typeparam>
|
|
|
|
/// <typeparam name="R">Return value of the inner command handler</typeparam>
|
|
|
|
public class IdentifiedCommandHandler<T, R> : IAsyncRequestHandler<IdentifiedCommand<T, R>, R> |
|
|
|
public class IdentifiedCommandHandler<T, R> : IRequestHandler<IdentifiedCommand<T, R>, R> |
|
|
|
where T : IRequest<R> |
|
|
|
{ |
|
|
|
private readonly IMediator _mediator; |
|
|
@ -37,7 +38,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands |
|
|
|
/// </summary>
|
|
|
|
/// <param name="message">IdentifiedCommand which contains both original command & request ID</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) |
|
|
|
public async Task<R> Handle(IdentifiedCommand<T, R> message, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
var alreadyExists = await _requestManager.ExistAsync(message.Id); |
|
|
|
if (alreadyExists) |
|
|
@ -55,6 +56,4 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |