Can two aggregate share parent child relationship or child should always be an entity and parent should be AR

101 views
Skip to first unread message

Vikas Pandey

unread,
May 4, 2018, 1:18:37 PM5/4/18
to DDD/CQRS
Hi

I was recently trying to design and Event sourced based system and struggling with Aggregate and Entity boundaries.
My problem is I am having a complex domain model with too many hierarchy. For example my domain model looks like this

class Parent {
name;
description;
List<Child1> children;
}

class Child1{
name;
List<ChildOfChild1> childrenOfChild1;
}

class ChildOfChild{
name;
}

Now my problem is how should I handle any events which are related to ChildOfChild. Should I apply them from Parent Aggregate root?
Can Child and ChildOfChild could also become aggregates with reference to parent aggregate identifier?

Why I am considering of keeping Child and ChildOfChild as separate AR because not every time someone asks for Parent, will be interested in Child and ChildOfChild data. Then why reduce performance and apply events for them as well. 

Daniel Hardt

unread,
May 4, 2018, 5:17:32 PM5/4/18
to DDD/CQRS
Hi there.

If you have a aggregate, with multiple entities, than you "replay" (apply) the events from you eventstore to the AR and the AR builds up the aggregate.
Also you only access your child entities through you AR. So if you must add a child entity, you had an methode like "AddChild" in your AR. And in this method, you convert a command to an event and apply it to you aggregate. So you had an event like "ChildAdded".
If you have to replay you events, at some point you get to this event and your apply method adds a new child into you child list. If the adding to the child list also had to add some child of child entities, than yeah you do that to. maybe you add another helper methods in your sub entities for this task, so that you AR-Apply method grows not too big.

Greetings
Daniel
Reply all
Reply to author
Forward
0 new messages