I am reading on DDD and I am trying to see how it would be applied in various situations.
So, let's take the example of a LoanApplication
. To submit such an application the user would need to fill-in various Sections
(e.g. PersonalDetailsSection
, BusinessAssetsSection
and so on).
Each of these sections is independent of the others, i.e. there are no invariants that will be violated if someone completely changes the PersonalDetailsSection
but not the BusinessAssetsSection
.
Moreover each of these sections is quite complicated on its own, with lots of one-to-many relationships so to me these sections are likely candidates for being different Aggregate Roots. The LoanApplication
could be another AggregateRoot containing just the IDs of the separate sections (aggregate root).
On the UI front, the user fills in the details of each section in a wizard style screen (first the personal details, then the business assets and so on). At any time he or she can save a temporary version of the LoanApplication
and in the end he or she can save a finalised version. Application finalisation means that it should be checked that all Sections contain valid information (e.g. no empty fields) and that no further changes to the application and each of the sections are allowed.
The first problem I have is that if I have each section as a separate AggregateRoot then whenever the user finalises the LoanApplication
, then a series of checks and changes need to be made to all AggregateRoots (including LoanApplication
). Is this an example of a Domain Service that I can use here with the purpose of making sure all sections contain valid data and finalising each one of them? Such a service would look like this
try {
businessSection.finalise();
personalSection.finalise();
loanApplication.finalise();
...
} catch (InvalidDataException e) {
//handle exception;
}
The second problem I have is about updating an Aggregate Root. An aggregate root may reference other aggregate roots by identity. So, let's say that a new Section
is created and gets a new id. Now the LoanApplication
aggregate root needs to reference the new id. Who is responsible for updating that in the LoanApplication
?
Thanks for any answers!