查找值是否应建模为聚合根? [英] Should lookup values be modeled as aggregate roots?
问题描述
作为域模型的一部分,假设我有一个 WorkItem
对象。 WorkItem
对象与查找值具有多种关系,例如:
As part of my domain model, lets say I have a WorkItem
object. The WorkItem
object has several relationships to lookup values such as:
WorkItemType
:
- UserStory
- 错误
- 增强
优先级
:
- 高
- 中
- 低
可能还有更多,例如状态
,严重程度
等...
And there could possibly be more, such as Status
, Severity
, etc...
DDD指出,如果聚合根中存在某些内容,则不应尝试在聚合根之外访问它。因此,如果我希望能够添加诸如Task之类的新WorkItemTypes或诸如Critical之类的新Priority,这些查找值是否需要是具有其自身存储库的聚合根?这似乎有些矫kill过正,尤其是当它们只是一个键值对时。
DDD states that if something exists within an aggregate root that you shouldn't attempt to access it outside of the aggregate root. So if I want to be able to add new WorkItemTypes like Task, or new Priorities like Critical, do those lookup values need to be aggregate roots with their own repositories? This seems a little overkill especially if they are only a key value pair. How should I allow a user to modify these values and still comply with the aggregate root encapsulation rule?
推荐答案
Landon,我认为我应该如何允许用户修改这些值并仍然遵守聚合根封装规则?唯一的方法是使这些值对聚合根。我知道这可能看起来有些矫,过正,但这是DDD将事情制动成小组件。
Landon, I think that the only way is to make those value pairs aggregate roots. I know that is might look overkill, but that's DDD braking things into small components.
我认为使用存储库是正确方法的原因是:
The reasons why I think using a repository is the right way are:
- 用户需要能够独立于工作项添加这些值对。
- 这些值对不没有本地唯一的身份
请记住,DDD只是一组准则,不是硬道理。如果您认为这是多余的,则可能需要创建一个将对作为值对象返回的查找。如果您没有在应用程序中而是通过数据库添加值对的功能,则可能会特别有效。
Remember that DDD is just a set of guidelines, not hard truths. If you think that this is overkill, you might want to create a lookup that returns the pairs as value objects. This might work out specially if you don't have a feature to add value pairs in the application, but rather through the database.
另外,很好的问题是!有很多关于这种情况的博客文章...但是,并非所有人都同意这样做的最佳方法。
As a side note, good question! There are quite a few blog posts about this situations... But not all agree on the best way to do this.
这篇关于查找值是否应建模为聚合根?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!