Replies: 3 comments
-
Thanks @sJhonny-e for the question! Interesting, but I see several issues related to this. First of all, I treat the command as a simple data structure, in your approach the constructor takes the responsibility of a more advanced process of creation. Constructor (in my opinion) should be very, very simple. The second issue, the most important, is the validation of such a command - in your approach when during the creation of value objects a business error for a single VO can be thrown. It means the client will always get the first exception. Structure validation should be "aggregate validation" (i.e. collect all errors instead of throwing the first one). This is the reason why to perform structure validation FluentValidation is used - it aggregates all data structure rules validation errors. The third issue is the one you have indicated - serialization will be more difficult, which will affect e.g. logging of commands. For me constructing Entities/ValueObjects in CommandHandler is normal behavior and responsibility of Application Layer. |
Beta Was this translation helpful? Give feedback.
-
thanks for your reply!
It seems to me that the concerns you raised above may be solved by:
|
Beta Was this translation helpful? Give feedback.
-
Hi again @sJhonny-e
The semantic of Command/Request-Response is that you have exactly one receiver of that Command - it means you will have only one Command Handling chain. Unlike an event where you have many recipients. The scenario when you have to create domain objects in several handlers in the same chain is very rare from my experience.
Validation is the one example, logging is the second. How would you log the whole Command object if you are not able to create it? I treat Commands as data structures so your suggestion about the Factory Method sounds better for me. However, for me, this implementation would be strange, it involves, in my opinion, more work and does not give more value. In my understanding CommandHandler is responsible for the orchestration and creating new objects is part of it. |
Beta Was this translation helpful? Give feedback.
-
Firstly, I really really like this project; I wish the code I work with every day was half as clean as this.
A small design suggestion - currently, the responsibility of parsing the primitive values of arguments is within the handler classes:
The handler is responsible, in addition to orchestrating the business logic to handle a command / query, for transforming raw values from the command into domain values. e.g. two dates into
Term
s, location data intoMeetingLocation
etc.Would it make sense to move this responsibility to the command objects themselves?
I've started looking into what that would look like on this branch.
Pros
Cons
Beta Was this translation helpful? Give feedback.
All reactions