274
CHAPTER 6 | Tackle Business Complexity in a Microservice with DDD and CQRS Patterns
You send a command to a single receiver; you do not publish a command. Publishing is for events
that state a fact
—
that something has happened and might be interesting for event receivers. In the
case of events, the publisher has no concerns about which receivers get the event or what they do it.
But domain or integration events are a different story already introduced in previous sections.
A command is implemented with a class that contains data fields or collections with all the
information that is needed in order to execute that command. A command is a special kind of Data
Transfer Object (DTO), one that is specifically used to request changes or transactions. The command
itself is based on exactly the information that is needed for processing the command, and nothing
more.
The following example shows the simplified
CreateOrderCommand
class. This is an immutable
command that is used in the ordering microservice in eShopOnContainers.
// DDD and CQRS patterns comment: Note that it is recommended to implement immutable
Commands
// In this case, its immutability is achieved by having all the setters as private
// plus only being able to update the data just once, when creating the object through its
constructor.
// References on Immutable Commands:
// http://cqrs.nu/Faq
// https://docs.spine3.org/motivation/immutability.html
// http://blog.gauffin.org/2012/06/griffin-container-introducing-command-support/
// https://learn.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/how-to-
implement-a-lightweight-class-with-auto-implemented-properties
[DataContract]
Dostları ilə paylaş: