Closed mwillema closed 5 years ago
Commanded enforces that one command can only target one aggregate.
Where you have an invariant that affects more than one aggregate you need to consider:
Have a look at the Domain modelling resources on the Commanded Wiki for more guidance.
IMO this is quite a limitation and may add accidental complexity. Application services / command handlers often need to orchestrate things and fetch multiple aggregates in order to execute a command. We agree that only one aggregate should be modified within a given transaction (other aggregates will be eventually consistent, process managers are used for that) but resolving relations is very important.
Event sourcing encourages us to model small aggregates, which increases the need to fetch the related ones to handle a given command.
I used this a lot in every past project I've been involved with :-)
Do you have an example which couldn't be acheived by querying a read model for related data?
Commanded is unlikely to ever support this feature.
Closing issue, but feel free to add any further comments @mwillema.
How can I fetch multiple aggregates when handling a command? For instance let's say we have the following:
Forum
andTopic
aggregatesOpenTopic{topic_id, forum_id, subject, text} command
The
OpenTopic
command is handled by theTopic
aggregate and opens / creates a new topic within a given forum. However in order to check invariants or perform some business logic, theTopic
aggregate needs the specifiedForum
. So, we need to resolve the relationship between a topic and its forum.In a pure DDD way my command handler would fetch the corresponding Forum from ForumRepository and pass it as a parameter to Topic. This way Topic can perform any business logic with the help of Forum before being saved, ie. change events being persisted.