识别聚合根
http://i51.tinypic.com/2ueqidt.jpg
让我们假设以下关系(图表)。基金公司有基金和账户。还有一个 FundAccount,它在帐户和资金之间创建多对多关系(以及关系级别的其他属性)。最后,一个账户有一个或多个受益人。
基金公司是一个聚合根,因为它位于金字塔的顶部。离开基金公司,账户和基金都无法存在。没有Fund和Account,FundAccount就不能存在;这是否使它们都聚合根?或者 Fund 仍然是唯一的聚合根,必须通过它才能对 FundAccount 实体执行操作?事实上,账户也有受益人,如果没有账户,受益人就无法存在,这是否也表明账户是聚合根?
此图中的所有实体都需要我的应用程序中的 CRUD 操作和屏幕。我提出这个问题的原因是大多数情况下每个 UI 屏幕都会存储它引用的行/实体的 ID。例如,用户单击包含资金的表格上的“详细信息”,我可能需要通过其 ID 检索资金。我的理解是,如果一个实体需要直接访问,那么它本身就是一个聚合根。然而,这将使许多实体默认聚合根。
根据上述问题的答案,我必须将这些操作映射到正确的聚合根的存储库。
http://i51.tinypic.com/2ueqidt.jpg
Let us assume the following relationships (diagram). A FundCompany has Funds, and Accounts. There is also a FundAccount which creates a many-to-many relationship (as well as other attributes at the relationship level) between Accounts and Funds. Lastly an Account has one or more Beneficiary.
The FundCompany is an aggregate root as it’s at the top of the pyramid. Neither Account nor Fund can exist without the FundCompany. FundAccount cannot exist without both Fund and Account; does that make them both aggregate roots? Or is Fund still the only aggregate root, having to go through it to perform operations on FundAccount entities? The fact that the Account also has Beneficiaries, which cannot exist without the Account, does that also signal Account being an aggregate root?
All of the entities on this diagram will require CRUD operations and screens in my application. The reason I’m bringing this is up is most often every UI screen will store the ID of the row/entity it’s referencing. So for example a user clicks “Details” on a table with Funds, I might need to retrieve a fund via its ID. My understanding is that if an entity needs direct access then it’s an aggregate root in itself. However this would make a lot of entities aggregate roots by default.
Based on the answers to above questions I have to map these operations to the proper aggregate root’s repository.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
整个图表是单一聚合 = 它具有单一聚合根 - 顶层
FundFamily
。如果Fund
和Account
无法在没有FundFamily
的情况下生存,那么它们就不能是聚合根。Whole your diagram is single aggregate = it have single aggregate root - the top level
FundFamily
. IfFund
andAccount
can't live withoutFundFamily
their can't be aggregate roots.