DDD - 在一个非常简单的博客模型中聚合根
作为练习,我尝试使用 DDD 在 .NET 中创建一个简单的博客应用程序。到目前为止,我有 User、Topic 和 Comment 类。但问题是如何将Comment与User和Topic联系起来?如果我说User和Topic是聚合根,那么Comment属于哪里呢?
As an exercise I am trying to create a simple blog app in .NET, employing DDD. So far I have User, Topic and Comment classes. But the problem is how to link Comment with User and Topic? If I say that User and Topic are aggregate roots, where does Comment belong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
聚合可能与其他聚合根有关联。
例如,评论可能与主题和用户都有关联。
无论如何,这就是我的建模方式,聚合根是一致性的边界。
主题不需要以任何方式与其评论保持一致,因此评论不需要成为该聚合的一部分。
用户不需要与他或她的所有评论保持一致,因此用户也不需要了解评论。
我将通过评论存储库获取特定主题的评论。
例如
Aggregates may have associations to other aggregate roots.
e.g. a comment may have an association to both topic and user.
Thats how I would model it anyway, aggregate roots are boundaries of consistency.
A Topic does not need to be consistent in any way with its comments, thus comments does not need to be part of that aggregate.
A user does not need to be consistent with all of his or her comments so users does not need to know about comments either.
I would fetch the comments for a specific topic by the comment repository.
e.g.