Consider a typical blog with Post and Comment objects.
For the demo DDD I created, I (so far) have found that both the Post and Comment objects were suitable for the same aggregate — the Post aggregate. But now I'm not sure.
In my controllers, I find, as expected, that I need to add and remove Comments from Posts . With my current model, I do not track Comment identification around the world (as the Blue Book suggests). You can expect my Comment removal action might look like this:
public ActionResult DeleteComment(int postID, int commentID)
Obviously, I need a Post ID to retrieve it from the repository and an identifier for a specific Comment on the Post that I want to delete.
My problem is the body of the DeleteComment( :
Is it possible to go through Post using the request mechanism to get Comment to be deleted? eg:
var comment = this._postRepo.WithID(postID).Comments .SingleOrDefault(c => c.ID == commentID); this._postRepo.Delete(comment); return RedirectToAction("detail", new { id = postID });
.. or should I choose Comment from a repo like this ?:
var comment = this._postRepo.CommentWithID(commentID)
.. or:
var comment = this._postRepo.CommentWithID(postID, commentID)
The two examples above may seem a little silly since I don't need a Post id if I can track Comment globally. But if I track Comment globally, shouldn't it have its own aggregate, and then is it right when Post and Comment seem to go together?