Reputation: 6973
I am working on a CQRS architecture. Right now we have all the pieces in place and we handle a command following this flow:
Is this the correct order? Can I execute the persistence logic inside the command handler and remove one event handler?
Upvotes: 1
Views: 896
Reputation: 692
As a sidenote the PersonLanguageChanged event should not contain the root aggregate, but rather just contain the information about what was changed.
The primary reason for not including the entire aggregate is to separate the event from the entity. For instance in a DDD scenario you might have another bounded context listening to this particular event and that bounded context has a different Aggregate for Person, since it might deal with the complexity of another domain such as billing etc.
This means that subscribers to not need to have a dependency to your specific aggregate.
Upvotes: 8
Reputation: 2893
Yes, you must execute the persistence logic inside the command handler, because:
You must therefore make sure that your aggregates are persisted to the database before the events are published. For, you can
Upvotes: 8