public class IdentifiedCommand : IRequest where T : IRequest {
public T Command {
get ; }
public Guid Id {
get ; }
public IdentifiedCommand
(T command, Guid id)
{
Command = command;
Id = id;
}
}
Then the CommandHandler for the IdentifiedCommand named
IdentifiedCommandHandler.cs
will
basically check if the ID coming as part of the message already exists in a table. If it already exists, that
com
mand won’t be processed again, so it behaves as an idempotent command. That infrastructure
code is performed by the
_requestManager.ExistAsync
method call below.
// IdentifiedCommandHandler.cs
public class IdentifiedCommandHandler : IRequestHandler, R>
where T : IRequest {
private readonly IMediator _mediator;
private readonly IRequestManager _requestManager;
private readonly ILogger> _logger;
public IdentifiedCommandHandler
(
IMediator mediator,
IRequestManager requestManager,
ILogger> logger)
{
_mediator = mediator;
_requestManager = requestManager;
_logger = logger ??
throw new System.
ArgumentNullException
(
nameof
(logger));
}
///
/// Creates the result value to return if a previous request was found
///
///
285
CHAPTER 6 | Tackle Business Complexity in a Microservice with DDD and CQRS Patterns