Say we have two aggregate roots in a domain model: Group and User.
Now, Users can be added to or removed from groups. Using the repository pattern, I only modelled the following two interfaces so far:
interface IGroupRepository
{
Group FindById(int groupId);
}
interface IUserRepository
{
User FindById(int userId);
IQueryable<User> GetGroupMembers(int groupId);
void AddUserToGroup(User user, Group group);
void RemoveUserFromGroup(User user, Group group);
}
Somehow, the doesn't feel right. I want to achieve a clean domain model and not end up with a mere data-access layer. What would be a better way to model the above?
EDIT: The root question here seems to be, is it OK with DDD's guidelines to treat User as a 'sub-object' while it at the same time is an aggregate root as well? As I understood DDD, it states that aggregate roots must only be retrieved and stored from one place (the repository) so that's why I get a bit confused.