protected virtual R
CreateResultForDuplicateRequest
()
{
return default (R);
}
///
/// This method handles the command. It just ensures that no other request exists with
the same ID, and if this is the case
/// just enqueues the original inner command.
///
///
name=
"message"
> IdentifiedCommand which contains both original command &
request ID
///
Return value of inner command or default value if request same ID was
found
286
CHAPTER 6 | Tackle Business Complexity in a Microservice with DDD and CQRS Patterns
command);
// Send the embedded business command to mediator so it runs its related
CommandHandler
var
result = await _mediator.
Send
(command, cancellationToken);
_logger.
LogInformation
(
"----- Command result: {@Result} - {CommandName} - {IdProperty}:
{CommandId} ({@Command})"
,
result,
commandName,
idProperty,
commandId,
command);
return result;
}
catch {
return default (R);
}
}
}
}
Since the IdentifiedCommand acts like a
business command’s envelope, when the business command
needs to be processed because it is not a repeated ID, then it takes that inner business command and
resubmits it to Mediator, as in the last part of the code shown above when running
_mediator.Send(message.Command)
, from the
IdentifiedCommandHandler.cs
.
When doing that, it will link and run the business command handler, in this case, the
CreateOrderCommandHandler
, which is running transactions against the Ordering database, as shown
in the following code.
// CreateOrderCommandHandler.cs