I would like to know how multiple aggregate root are created in CQRS.
Example: I have a handset aggregate root and Simcard aggregate root. The id from these aggregate should be part of subscription aggregate root .
i need to create a Subscription aggregate based on SimCard and an Handset.SimCard and Handset aggregate do not exist in the system . they are created when Subscription is created . When Subscription is deleted SimCard and Handset is not deleted. Business reason: user might insert different SimCard into the same Handset or the handset supports dual SimCards.
business rule : Phone number should be unique. Handset serialNumber should be unique. One subscription is associated with one handset One handset is associated with 1 or more phone number.
Class Handset {
String serialNumber
Handset(UUID id,serialNumber){
super(id);
this.serialNumber=serialNumber;
}
}
Class SimCard{
String phoneNumber
SimCard(UUID id, String phoneNumber){
super(id);
this. phoneNumber= phoneNumber;
}
}
Class Subscription {
UUID id
UUID deviceid
UUID simCardid
Subscription (UUID id, UUID deviceid, UUID simCardid){
Super(id);
This. Deviceid= deviceid;
This. simCardid= simCardid;
}
}
You can use a Saga for this. See:
Also take a look at Don’t Create Aggregate Roots
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With