Architecture 共同事务在哪里?

Architecture 共同事务在哪里?,architecture,domain-driven-design,dao,ddd-service,Architecture,Domain Driven Design,Dao,Ddd Service,域驱动方法中的公共服务存放在哪里 例如,有时我们可能需要一些常用函数,如getcountrylist、getstatelist、getcitylist(或主表中的一些其他数据),以在UI的不同页面/模块中显示下拉列表。假设这些数据存在于数据库中,那么我们需要在哪里使用这些函数 我可以将这些函数保存在域/Common/CommonServices.php中吗(我的意思是域层内部是好的?) (或) 我是否可以将这些函数保存在Infra/Common/CommonServices.php中(在这种情况

域驱动方法中的公共服务存放在哪里

例如,有时我们可能需要一些常用函数,如getcountrylist、getstatelist、getcitylist(或主表中的一些其他数据),以在UI的不同页面/模块中显示下拉列表。假设这些数据存在于数据库中,那么我们需要在哪里使用这些函数

  • 我可以将这些函数保存在域/Common/CommonServices.php中吗(我的意思是域层内部是好的?) (或)

    我是否可以将这些函数保存在Infra/Common/CommonServices.php中(在这种情况下,我需要直接从Infraservice层连接到dao层,我觉得这是不正确的?)

  • 包含这些常用函数的文件的正确名称/建议名称是什么。(CommonServices.php(或)CommonHelper.php(或)CommonUtils.php(或)MetadataService.php(或)您的任何建议)


  • 如果您在不同的有界上下文中确实需要相同的数据,并且使用相同的存储库检索它们,那么在DDD中有一种称为共享内核的东西。共享内核是一个地方,当您将重叠的内容放在少数有界上下文中时,引用DDD Quick:


    无论如何,如果共享内核变得太大,那么建模可能会有问题。尽量使共享内核尽可能小。

    这种行为与数据有关,因此我会将其放在一个特殊的存储库或读取模型facade中。您也可以使用域服务,但服务是一个过载的术语,它不传递数据访问方面

    如果您采用CQRS方法,我建议将其放在单独的读取模块中。否则,您可以像其他repo一样,将接口保留在域层,将实现保留在基础架构中


    (编辑)为了让事情更清楚一点,控制器可以直接调用这个外观,因为它只是只读访问,而不是操纵聚合,聚合可能必须通过控制应用程序事务的应用层服务。

    这是否意味着这些函数可以放在Domain/Shared/CommonServices.php中?
    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.