绕过聚合根 [英] Bypassing Aggregate Root

查看:203
本文介绍了绕过聚合根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么情况下可以得到聚集只读集合无需通过根得到它?我的模型做一些这方面,现在,我想知道如果这是一个可以接受的设计。谢谢

Is it okay to get a read-only collection from an aggregate without going through the root to get it? My model does some of this right now and I was wondering if that's an acceptable design. Thanks

编辑:

下面是一个例子

我有一个叫做UserAccount的聚合根实体和另一个叫VideoStore聚合根。用户可以有多个存储他们是分开的视频商店可以有许多用户。一个非常基本的多到很多,但因为很多一对多网桥表中包含状态信息,所以它是一个实体,以及它不是。所以,我有一个桥梁实体,称为UserVideoStores及其聚合根VideStore(一到多)的孩子。

I have an aggregate root entity called UserAccount and another aggregate root called VideoStore. Users can have multiple stores they are apart of and video stores can have many users. A very basic many-to-many, but it's not because the many-to-many bridge table contains state information so it has to be an entity as well. So, I have an bridge entity called UserVideoStores and its a child of the aggregate root VideStore (one-to-many).

现在当我一个用户登录要查找它们是VideoStores分开的,并显示信息给他们。我可以很容易地做到这一点通过使UserAccount实体有直接(一到多)参照孩子,UserVideoStores,总根VideoStores的。它似乎更容易这样做,那么必须使用HQL查询,并从该图时发现存储用户的分开的底部进行搜索。

Now when a user logs in I want to lookup which VideoStores they are apart of and display that info to them. I can easily do this by making the UserAccount entity have a direct (one-to-many) reference to the child, UserVideoStores, of the aggregate root VideoStores. It seems easier to do this then have to use an HQL query and search from the bottom of the graph up to find which stores the user is apart of.

这是否有道理?

编辑:

好吧,我想出了一个解决方案,使我的模型更清洁。我不直想一些我的设计,我学会了如何使用NHibernate的好一点点帮我想出了一个解决方案。谢谢

Well I came up with a solution to make my model cleaner. I wasn't thinking straight about some of my designs and I learned how to use nHibernate a little bit better to help me come up with a solution. Thanks

推荐答案

Evans说的根源是聚集的唯一成员是外界对象可以持有引用......(第127页)

Evans says "The root is the only member of the AGGREGATE that outside objects are allowed to hold references to..." (p. 127)

我的理解是,总应显示为外物的单位。此外,得墨忒耳定律似乎适用。底线,我不认为这是可以接受的。

My understanding is that the aggregate should appear as a unit to outside objects. Also, the Law of Demeter would seem to apply. Bottom line, I don't think it's acceptable.

这篇关于绕过聚合根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆