Imagine you have a Computer entity, this entity also cannot live without its Software entity and Hardware entity. These form the Computer
aggregate, the mini-ecosystem for the Computer portion of the domain.
Aggregate Root is the mothership entity inside the aggregate (in our case Computer
), it is a common practice to have your repository only work with the entities that are Aggregate Roots, and this entity is responsible for initializing the other entities.
Consider Aggregate Root as an Entry-Point to an Aggregate.
In C# code:
public class Computer : IEntity, IAggregateRoot
{
public Hardware Hardware { get; set; }
public Software Software { get; set; }
}
public class Hardware : IEntity { }
public class Software : IValueObject { }
public class Repository<T> : IRepository<T> where T : IAggregateRoot {}
Keep in mind that Hardware would likely be a ValueObject too (do not have identity on its own), consider it as an example only.