Folks, The problem statement can be found as follows, Background:
- the application collect user information, which can be modeled by AggregateA, and AggregateB;
- AggregateA contains a collection of AggregateB
- AggregateA/B contains a small number of Entities
- the application persists AggregateA then AggregateB (the primary key of AggregateA is used an input to persist AggregateB)
Question: in the service layer, is there any alternative to this?
def add_user_info(varA, varB):
A_ID = repoA.add(varA)
repoA.commit()
repoB.add(A_ID, varB)
repoB.commit()
is it possible to have a single commit in this insertion?
Consider to use an Unit of Work pattern.
This way, you'll also avoid side effects turning all the procedure an single operation, and if it's fails, the repoA won't generate trash in your database.
An example of UoW here