cqrs-sample icon indicating copy to clipboard operation
cqrs-sample copied to clipboard

How to create a more complex aggregate with more than one entity

Open Heucles opened this issue 8 years ago • 1 comments

Can you put together a sample of what it would look like an aggregate with more than one entity, something like:

  • Car (root)

    • Wheel
    • Tire
    • Engine (root of its own aggregate)
  • Customer (root)

    • Car (root of its own aggregate)
    • Address

I am having some trouble setting this up, since Customer events can have an effect over the Car aggregate. Can you point me into the right direction?

Heucles avatar Aug 06 '17 23:08 Heucles

Hi @Heucles!

An aggregate:

  • handles commands and emit events
  • ensures the validity of invariants
  • is the transactional boundary
  • runs business processes
  • makes decisions
  • focus on verbs (doing) => intention

I would recommend not to start with the entities, start with the intention. Which commands should be sent to the same aggregate to ensures the validity of invariants?

Little hint: Try first to not give your aggregate a name. (first catch intention, then give a name)

If you want, you can even try to do an event storming (by @ziobrando) => https://techbeacon.com/introduction-event-storming-easy-way-achieve-domain-driven-design ;-)

adrai avatar Aug 07 '17 05:08 adrai