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
Dostları ilə paylaş: