If I understand what you are attempting, you are adding a Comment() to the IList in question which is attached to a Post(). And within your Post(), you are looking for any new Comment()s in the IList and saving them. Having the Post() object control its child objects, such as Comment()s, does go down the road of DDD.
I am still new to these patterns myself; but personally, I lean towards the concept that any entity that has metadata, I treat as its own entity model; therefore, I create my own repostiory for each entity model.
Post()
PostRepository : IPostRepository
Comment()
CommentRepository : ICommentRepository
Now, having a IList Post.Comments I believe violates the Law of Demeter by allowing you to execute Post.Comments.Add().
I believe a solution to your problem would be not add to the IList, but instead create methods on the Post() to handle the comments related to that Post instance:
Post.AddComment()
Post.FetchComments()
Post.DeleteComments(IList<Comment> comments)
Then within your Post() object, you would wire up your ICommentRepository (most likely with a ServiceLocator, or I prefer Castle Windsor) and handle adding and deletion of them.
ICommentRepository.AddByPostID()
ICommentRepository.FetchByPostID()
ICommentRepository.Remove(int commentID)
Again, I am still new to the DDD patterns; but, I believe this is keeps the Seperation of Concerns valid and masks the underlying logic by keeping it within the Post()'s concern to "only handle actions on comments related to this Post object".
The complete Post() class would be something like this:
private ICommentRepository _commentRepo;
public class Post
{
public Post(ICommentRepository commentRepo)
{
// Or you can remove this forced-injection and use a
// "Service Locator" to wire it up internall.
_commentRepo = commentRepo;
}
public int PostID { get; set; }
public void DeleteComments(IList<Comment> comments)
{
// put your logic here to "lookup what has been deleted"
// and then call ICommentRepository.Delete() in the loop.
_commentRepo.Remove(commentID);
}
}
Please comment if others have opinions or changes.