在域驱动方法中 - 在哪里保留常用服务?
例如,有时我们可能需要具有常见功能,如getcountrylist,getstatelist,getcitylist(或来自MASTER表的其他一些数据),以显示UI的不同页面/模块中的下拉列表。假设这些数据是否存在于数据库中,那么我们需要具备这些功能。
我可以将这些功能保存在Domain / Common / CommonServices.php中(我的意思是在域内层是好的吗?) (或)
我可以将这些功能保存在Infra / Common / CommonServices.php中(在这种情况下,我需要直接从Infraservice层连接到dao层,我觉得这不正确吗?)
包含这些常用功能的文件的正确名称/可建议名称是什么。 (CommonServices.php(或)CommonHelper.php(或)CommonUtils.php(或)MetadataService.php(或)您的任何建议)
答案 0 :(得分:4)
如果您确实需要在不同的有界上下文中使用相同的数据并使用相同的存储库检索它们,那么在DDD中就会出现一种称为 SHARED KERNEL 的内容。当你在几个有限的上下文中放置重叠的东西时,SHARED KERNEL是一个地方,引自 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.
无论如何,如果你的SHARED KERNEL增长太大,那么你的建模可能会有问题。尽量保持SHARED KERNEL尽可能小。
答案 1 :(得分:0)
行为与数据有关,所以我将它放在一个特殊的Repository或Read Model facade中。你也可以使用域名服务,但服务是一个超载的术语,并没有传达IMO的数据访问方面。
如果采用CQRS方法,我建议将其放在单独的读取模块中。否则,您可以将接口保留在Domain层和Infrastructure中的实现中,与其他repos一样。
(编辑)使事情更清晰一点,这个外观可以由控制器直接调用,因为它只是只读访问,而不是操纵可能必须通过应用程序层服务来控制应用程序事务的聚合。