I am modeling an inventory application where items are managed and grouped into a containers and assign one unique number which will identify the inventory instance and can easily manage using RF IDs in warehouse. In these scenarios a container can hold another container or more which will point to parent container to form a hierarchical order or parent child relationship. So my question is If I model container as an AggregateRoot with a collection of child Containers by reference, will it break the DDD rule. The reason for treating this way due to the transaction boundary where I can adjust the inventory movement or manage quantities when a child container is moved or added into Parent container by using parent RF ID scan. Here is my sample code
public class Container:AggregateRoot
{
public virtual string Id{get;protected set;}
public virtual ScanId {get;protected set;}
public List<Container> ChildContainers {get;set;}
public void Detach(Container containerToAttach){
//Todo Adjustments
ChildContainers .Remove(containerToAttach);
}
public void Attach(Container containerToAttach){
//Todo Adjustments
ChildContainers .Add(containerToAttach);
}
}