【问题标题】:Where to keep the common services?在哪里保留公共服务?
【发布时间】:2014-09-13 21:23:28
【问题描述】:

在领域驱动方法中 - 在哪里保留公共服务?

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

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

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

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

【问题讨论】:

    标签: architecture domain-driven-design dao ddd-service


    【解决方案1】:

    如果您确实需要不同限界上下文中的相同数据并且使用相同的存储库检索它们,那么在 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.
    

    无论如何,如果您的共享内核变得太大,那么您的建模可能会出现问题。尽量保持共享内核尽可能小。

    【讨论】:

    • 是不是可以把函数放在Domain/Shared/CommonServices.php里面?
    【解决方案2】:

    该行为与数据有关,因此我会将其放置在特殊的存储库或读取模型外观中。您也可以使用域服务,但服务是一个重载术语,并没有传达 IMO 的数据访问方面。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-07
      • 2017-11-06
      • 2013-04-01
      • 2019-11-09
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多