在领域驱动方法中--在哪里保留公共服务?
例如,有时我们可能需要一些通用的函数,如getcountrylist、getstatelist、getcitylist (或母版表中的一些其他数据)来显示UI的不同页面/模块中的下拉列表。假设这些数据存在于数据库中,那么我们需要这些函数。
发布于 2014-09-13 21:44:43
如果您确实需要在不同的有界上下文中使用相同的数据,并且使用相同的存储库检索它们,那么在DDD中有一个叫做共享内核的东西。共享内核是在少数有限制的上下文中放置重叠的东西的地方,这是DDD Quick的引语
The purpose of the Shared Kernel is to reduce duplication, but still keep two separate
contexts. Development on a Shared Kernel needs a lot of care. Both teams may modify
the kernelcode, and they have to integrate the changes.
If the teams useseparate copies of the kernel code, they have to merge the codeas soon
as possible, at least weekly. A test suite should be inplace, so every change done to
the kernel to be tested right away. Any change of the kernel should be communicated
to another team, and the teams should be informed, making them aware of the new
functionality.无论如何,如果您的共享内核变得太大,那么您的建模可能会有问题。尽量保持共享内核尽可能小。
发布于 2014-09-15 12:16:34
这种行为与数据有关,所以我会将其放在一个特殊的存储库或中。您也可以使用域服务,但是Service是一个重载的术语,不能传递数据访问方面的信息。
如果采用CQRS方法,我建议将其放在单独的读取模块中。否则,您可以将接口保留在域层中,并在基础设施中实现,就像其他repos一样。
(编辑)为了使事情更清楚一点,这个外观可以由控制器直接调用,因为它只是只读访问,而不是操纵可能必须通过控制应用事务的应用层服务的聚合。
https://stackoverflow.com/questions/25827853
复制相似问题