I have two Aggregates called CompanyAggregate
and ProfileAggregate
and their Aggregate Root are Company
and Profile
respectively, a Company can have many Profiles. The view responsible for creating Companies has the possibility to create Profiles too at the same time (there is a list and an append button, it is a View requirement), so when the user clicks the save button both Aggregates should be saved. The question is what is the best approach to achieve that?
I have a workflow on mind that is like the following:
- Call Company's API to create the Company;
- Get the created Company's Id;
- Call Profiles' API to create each Profile;
- Done.
Should those calls be made from the client side or from our API Gateway (API Decomposition opposed to Composition) OR should I use a domain event? In the latter case I would have to pass Profile data to the Company Aggregate just to raise a domain event leading to a boundary violation.
Some will say Profile should go inside Company Aggregate, but that is not the case as Profile can be directly referenced by another Roots.