I have a MeetingRoom aggregate-root (at least I believe it to be) that contains a list of Employees and there is a business requirement for each Employee to be able to set a MeetingDate, but this can only be set if all of the employees in that Meeting room are also ready for a meeting (each employee must have Employee.IsReadyForMeeting == true).
The issue I am having is being able to enforce this relationship, because the MeetingDate is a property of an Employee but the rules belong to the MeetingRoom, I have something like this:
public class MeetingRoom
{
public void SetMeetingDate(Employee employee, DateTime date)
{
if (!AllEmployeesAreReady)
{
throw new SomeMeaningfulException();
}
employee.SetMeetingDate(date);
}
public bool AllEmployeesAreReady
{
get
{
return false;
}
}
}
The issue I have with this is that because the Employee MeetingDate needs to be set by the MeetingRoom object it must necessarily have a "setter" and then because of this any instance of the Employee class would be able to set this value without the rules of the MeetingRoom (AllEmployeesAreReady) it can lead to an employee having a MeetingDate which is not valid in the context of the meeting room. I think there is an issue with either the aggregate root or bounded context (or both) I have obviously made a mistake but it is not clear to me with my limited DDD experience.
Aucun commentaire:
Enregistrer un commentaire