Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple aggregate root creation in one single transcation in CQRS

Tags:

cqrs

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; 
     } 
     }
  • Hide quoted text -
  • Show quoted text
like image 872
Steve Avatar asked Sep 12 '10 11:09

Steve


1 Answers

You can use a Saga for this. See:

  1. Saga Persistence and Event-Driven Architectures
  2. A Messaging Saga
  3. Rhino Service Bus: Saga and State

Also take a look at Don’t Create Aggregate Roots

like image 134
Seva Parfenov Avatar answered Jan 03 '23 16:01

Seva Parfenov