Help choosing my DDD aggregate roots within a provided scenerio?
I'm fairly new to DDD and have read a few articles about the concept so pardon if I'm lacking some knowledge. I'm curious on how this example should be modeled with aggregate roots.
The basis is: There is an Employee, a Meeting and Comments. Each Employee can attend a Meeting where they can make Comments. The Comments are tracked according to Employee and Meeting. Every Meeting and Employee have unique identifiers.
If I wanted to display all Comments from a Meeting, regardless of the Employee, would I first have to get all the Employees that belong to that Meeting and then sort through the Comments to only show ones that match the Meeting Id?
Meeting can't be my aggr开发者_如何学编程egate root because when I need a list of Employees, I certainly do not want to have to go through meetings to get that. Maybe each one is an aggregate root, but Comments do not make sense really outside an Employee. I'm looking for ideas on how to better approach this scenario.
// Datebase tables
Meeting
Employee
Comment - Contain EmployeeId and MeetingId
public class Employee
{
public List<Comment> Comments { get; set; }
}
public class Meeting
{
public List<Employees> Employees { get; set; }
}
Thanks in advance for the help.
Employee and Meeting are your aggregate roots, and you'll have to create a repository for your aggregate roots.
Comments can be a property of Meeting. I think it is useless to retrieve the comments from an Employee, without being related to a Meeting ? I don't think Comments do not have any meaning when you don't know its 'context' (== Meeting) ?
By doing so, your class model will be something very similar to what Chris Marisic proposes.
Next to those classes, you could have the following repositories:
public class EmployeeRepository
{
public IList<Employee> GetAll() {}
}
public class MeetingRepository
{
public IList<Meeting> GetAll(){}
public IList<Meeting> GetMeetingsAttendedByEmployee( Employee emp ){}
}
I would probably design this as
public class Comment
{
public string Message {get;set;}
public Employee {get;set;}
public Meeting {get;set;}
}
public class Employee
{
//public List<Comment> Comments { get; set; } <- why does this matter?
}
public class Meeting
{
//public List<Employee> Employees { get; set; } <- why does this matter?
public List<Comment> Comments { get; set; }
}
精彩评论