Question

I need to implement a project with CQRS, however I'm in doubt about what entities get a corresponding command and query classes.

If I have classes A, B and C, being that A is my aggregate root and the others are child entities in my aggregate, what classes should have command and query classes?

I mean, should I have a QueryA, QueryB and QueryC, or should I have only QueryA, which will bring the child data using lazy loading, for instance?

For repositories, as my understanding of the domain model, I'm considering only a RepositoryA (for my aggregate root).

Was it helpful?

Solution

Queries are not per aggregate, they are on a per view basis. For instance say you have a customer account and want to display

  1. a list of accounts
  2. account details with confidential info (e.g. credit card details)
  3. account details without confidential info

This would be three queries, one for every view. And usually without such painful things like lazy loading. Either you need some piece of information for a specific view or you don't.

Commands are not per aggregate as well. You would have a command for every behavior. Like OpenAccount, CloseAccount, MergeAccounts, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top