我已经设置了一个正在使用 ORM 填充的域项目。该域包含不同的聚合,每个聚合都有自己的根对象。
我的问题是应该如何处理跨越聚合边界的属性?
- 这些属性是否应该简单地忽略边界,以便有界上下文 A 中的域对象可以引用上下文 B 中的对象?
- 或者,是否应该没有从上下文 A 到 B 的直接链接,并且上下文 A 中的对象是否具有“int ContextBId”属性,可用于通过 B 聚合根从 B 获取域对象?
- Or ...
一个例子:
上下文 A = 用户
情境 B = 游戏
在 - 的里面Users
上下文有一个对象UserOwnedGames
。这个对象有一个属性User
这是对同一对象的引用Users
语境。该对象还有一个属性Game
这显然不在用户中,而是在Games
语境。
这种关系会(或应该?)是什么样子?数据库中很清楚(即2个外键),但是代码应该是什么样的?
听起来像你的User
上下文还需要一个Game
实体。但请注意,这不一定相同Game
实体是根Game
语境。这两个有界上下文可能对什么有不同的想法Game
是什么,以及它有什么属性。只有身份将两个 Game 对象联系在一起。
User Context
{
Aggregate Root User
{
Identity;
Name;
OwnedGames : List of Game value entities
}
Value Entity Game
{
Identity;
Name;
}
}
Game Context
{
Aggregate Root Game
{
Identity;
Name;
Owner : User value entity
HighScore : int
TimesPlayed : int
... A whole bunch of other properties which are not relevant in the User context
}
Value Entity User
{
Identity;
Name;
// No OwnedGames property, in this context we don't care about what other games the user owns.
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)