Take a class which has relations with a couple of other classes. The first class can be seen as the aggregate(root). Seen from the point of the service layer how would one best split the calls?
- Call the repository of the aggregate for the entire object graph and call from that particular repository other repositories to handle the saving of the relations (one repository per type of class.
- Call the repository of the aggregate for the entire object graph and handle all in that one method (so saving of all the relations in that same method).
- From within the service layer, call the repositories for the aggregate and then directly after that, again from the service layer, call the repositories of the related classes.
- Add an extra layer in between the service and the repositories and from within that extra layer do like in option 3.
I've seen already all 3 possible solutions in production code but I'm interested in the cleanest solution and a reason as to why one would opt for that approach.