For the purpose of separating different functionality into different classes, I have two following Aggregates:
- AssignTask ()
- ReassignManager ()
- Deactivate (string reason)
- GetReasonForDeactivation ()
- Reinstate ()
Both aggregates share the same root, dbo.Employee.
EmployeeID servers as a primary key for both Aggregates.
The repository instantiates the first one, or the second one based on a boolean flag dbo.Employee.IsActive.
Since I follow the rule that only one aggregate can be modified in one transaction, I will never encounter a situation where I load both aggregates with same ID, ending up with InactiveEmployee with ID 3 and ActiveEmployee with ID 3 in same transaction.
Is this good DDD? Does DDD allow for having two aggregates with same root? Can we differentiate Aggregate types based on a flag?
When I said that both aggregates share the same root, what I meant was that both Aggregates represent a row in dbo.Employee table.
In my understanding, a root of the Aggregate is the entity which is uniquely defined in our domain. It does not mean that that entity has to exist as a real class, it's identity is what matters. Every other Aggregate that wants to reference Inactive/ActiveEmployee will hold a reference to the EmployeeID, not the reference to object instance.