remi bourgarel
remi bourgarel

Reputation: 9389

Should Command / Handles hold the full aggregates or only its id?

I'm trying to play around with DDD and CQRS.

And I got this two solutions :

For now I have the id in the commands and the full model in the events (I trust my unit of work for caching the Load(aggregateId) so i won't execute the same request 100 for 1 command).

Is there a right / better way ?

Upvotes: 1

Views: 266

Answers (1)

eulerfx
eulerfx

Reputation: 37719

Yes your current approach is correct - reference the aggregate with an identity value on the command. A command is meant to be serialized and sent across process boundaries. Also, a command is normally constructed by a client who may not have enough information to create an entire aggregate instance. This is also why an identity should be used. And yes, your unit of work should take care of caching an aggregate for the duration of a unit of work, if need be.

Upvotes: 8

Related Questions