thenativeweb / cqrs-sample

CQRS, EventSourcing, (DDDD) Sample in node.js
148 stars 50 forks source link

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

Open Heucles opened 7 years ago

Heucles commented 7 years ago

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

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?

adrai commented 7 years ago

Hi @Heucles!

An aggregate:

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 ;-)