开发者

DDD Aggregate Question (.NET, EF)

My domain model (simplified) contains a story, team, members, and comments. I'm at the point where I need to allow the user to write a comment about a story and I have the comment entity belonging to the story aggregate,开发者_开发问答 so I have a method on Story called 'AddComment'. It seems silly here to load the aggregate to save a comment, so I was wondering if I should remove this entity from the aggregate or is there something here I'm missing? I'm sure I will run into more than one of these types of scenarios, so any help would be great!

Thanks


Marco, resist the urge to allow the technical implementation to drive a change like that to your domain model. Every time I've done that, I've later regretted it. If Comments only exist within Stories, then keep Story as the aggregate and bend the technology to match the model.


If the comment cannot exist without a story then why does it seem silly to load the story to save a comment? And you are not actually saving the comment, you are adding it to a story, and then you save the story.

Usually when you find yourself having these filings that you do unnecessary stuff to perform an operation it is an indication that your domain model might need more refinement. Go over all your consistency boundaries requirements ( Aggregates ), review each bounded context in your model and maybe things you missed on the first pass will surface.

As Eric Evans sais, DDD is an iterative process. You will fail the first few times :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜