开发者

DDD - aggregate roots in a very simple blog model

开发者 https://www.devze.com 2023-01-30 04:35 出处:网络
As an exercise I am trying to cr开发者_开发问答eate 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?

As an exercise I am trying to cr开发者_开发问答eate 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?


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.

var comments = commentRepo.FindCommentsForTopic(someTopic); 
//or by topic id for pragmatic reasons.
0

精彩评论

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