jeudi 27 mai 2021

How to split a big Aggregate Root to smaller?

I´m developing a domain layer that has a specific Aggregate Root. That aggregate root consists of a Company that has various types of related persons. Something like this:

public class Company
{
   public virtual ICollecion<PersonType01Entity> Person01 {get; private set;}
   public virtual ICollecion<PersonType02Entity> Person02 {get; private set;}
   public virtual ICollecion<PersonType03Entity> Person03 {get; private set;}

   public void AddPersonType01(PersonType01Entity p) 
   { 
      if(Person01.Any(c => c.id == p.id )
         throw new Exception();
   }
   // more code
}

Imagine that I need to do this type of checking for every person type, and other invariants checks. My Aggregatte Root entity became to big and I´m do not know how to split it to be smaller. Any suggestions on this?

Aucun commentaire:

Enregistrer un commentaire