There are several complex domain objects in my CQRS application. When they are created, all properties of the object are directly specified by the user, therefore
CreateFooCommand has about 15 properties.
FooCreatedEvent also has 15 properties , because I need all the properties of the entity on the read side.
Since the command parameters must be sent to the domain object, and FooCreatedCommand should not be transferred to the domain,
there is a manual mapping from CreateFooCommand to the domain.
Because the domain must create a domain event,
This is another mapping from Foo domain properties to FooCreatedEvent.
On the reading side, I use DTO to represent the Foo structure, as it is stored in my reading model.
Thus, the event handler that updates the reading side introduces a different mapping from the event parameters to the DTO.
To implement a simple business example, we have
- Two redundant classes
- Three mappings are basically the same property
I was thinking about getting rid of the command / event arguments and pushing the DTO object, but that would mean that the domain can receive or create the DTO and assign it to the event.
Sequence:
REST Controller --Command+DTO--> Command Handler --DTO--> Domain --(Event+DTO)--> Event Handler
Any ideas on how to reduce CQRS pain in implementation?