处理DDD中的嵌套聚合 [英] Dealing with nested aggregates in DDD
问题描述
我刚开始使用DDD,但在弄清楚如何适应数据的关系性质时遇到了一些麻烦。我有被认为是我的聚合根的人,但是聚合也有自己的聚合。不想违反Demeter法则,我想知道我是否正在考虑这个错误,并希望某些DDD专家可以提供一些见识。
I'm just getting started in DDD, and I'm having some trouble figuring out how to accommodate the relational nature of my data. I have what I believe would be considered my aggregate root, but the aggregate also has an aggregate of its own. Not wanting to violate the Law of Demeter, I'm wondering if I'm thinking about this wrong and am hoping that some DDD expert can offer some insight.
我的总计根是我的 Account
对象,该对象具有许多
My aggregate root is my Account
object, which has an aggregate of numerous AccountElement
entities, which are themselves logical groupings of individual ProductComponent
entities.
AccountElement
Account
没有任何意义,因此我对 Account
对象是我的聚合根的结论感到满意,预期该实体具有总计 Elements
属性。我感到困惑的是 ProductComponent
集合。此汇总在 AccountElement
之外没有任何意义,而 really 在 Account $ c $之外没有任何意义c>。
An AccountElement
outside of the context of an Account
has no meaning, so I'm comfortable with my conclusion that the Account
object is my aggregate root, and I anticipate that entity having an aggregate Elements
property. It's the ProductComponent
collection that has me confused. This aggregate has no meaning outside of an AccountElement
, and really has no meaning outside of an Account
.
我不认为我应该通过点我的方式来访问单个 ProductComponent
对象,像这样:
I don't think I should be accessing individual ProductComponent
objects by dotting my way to it, like:
var reference = account.Elements(0).ProductComponents(0).ReferenceCode;
但同时(从域的角度来看)访问 ProductComponent
直接来自 Account
实体。
But at the same time it doesn't make sense (from a domain perspective) to access a ProductComponent
directly from an Account
entity.
我是确保在不了解我的域的情况下很难理解所有这些信息,但是我希望它足以获得一些好的反馈。
I'm sure that this is all a little difficult to comprehend without knowledge of my domain, but I'm hoping it's enough to get some good feedback.
推荐答案
Robert链接到的文章很好。我要补充的是,如果ProductComponent仅存在于AccountElement的上下文中,而AccountElement仅存在于Account的上下文中,则通过扩展ProductComponent处于Account的上下文中。
The article Robert linked to is a good one. I would add that if ProductComponent exists only in the context of AccountElement and AccountElement exists only in the context of Account, then by extension ProductComponent is in the context of Account.
这篇关于处理DDD中的嵌套聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!