开发者

multiple aggregate root creation in one single transcation in 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)开发者_StackOverflow中文版; 
             This. Deviceid= deviceid; 
             This. simCardid= simCardid; 
     } 
     }
  • Hide quoted text -
  • Show quoted text


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜