Let's assume a project presenting those specifications:
Employee
can organize a Meeting
inviting other Employee
s.Employee
can accept the invitation to participate to the Meeting
, while the number of max Participation
s isn't exceeded.Manager
of the Employee
creator can cancel the Meeting
at any time.IMO, the invariants are:
exists
as long as the creator (Employee
) exists (not deleted or flag as deleted).Meeting
containing a number of participants superior to the limite intended.Employee
that cancels its created Meeting
should have also this Participation
s canceled /deleted.Manager
cancels an Employee
's Meeting
, both the Meeting
and the Participation
s should be deleted.Should I make:
Employee
an Aggregate Root, containing the collection of its created Meeting
s. Meeting
being thus an inner entity of Employee
and containing a collection of Participation
s.Employee
s.Thus there would be just to Aggregate Roots:
Employee
and Manager
.
Indeed, a Manager could be fired and then is not part of an invariant with the Employee
, and vice versa.
In details:
_ Employee
would provide a method createParticipation
, encapsulating checks for the important rules like whether the number max of participants is exceeded.
_ Employee
would provide also a Factory to create Meeting
, allowing to always assign the correct EmployeeId
to the Meeting
.
_ Only two repositories would be created: EmployeeRepository
and ManagerRepository
, avoiding direct access to respective inner parts.
(that deals only with creations, deletions would be similar)
Therefore, in order to create a Meeting
's Participation
, my entry point would be the creator(Employee
) that I retrieve through the EmployeeRepository
.
Does it make sense in order to follow strict DDD practice?
Your Employee aggregate is way too big. This creates concurrency issues. What would happen if two employees accept the invitation in the same time? One transaction would be rolled back because they try to modify the same aggregate. Unless you designed some fancy conflict resolution logic.
Instead, consider Participation and Meeting to be separate aggregates.