领域驱动设计 (DDD):领域或基础设施问题

Domain Driven Design (DDD): A Domain or Infrastructure Concern

我沉浸在 DDD 中,对什么属于域以及什么是基础设施问题有疑问。

描述域的简化示例:

应用程序中的上下文之一是关于允许用户检查网页以获取特定信息的便利功能。即..

"A user wants to examine a web page and determine whether the phrase "lorem ipsum" 出现在什么位置。"

我们将使用Selenium作为匹配词组的底层技术。

在深入研究 DDD 之前,我会创建一个如下所示的 Class(下面的 Python,但语言无关紧要):

class Page:
def __init__(self, url, environment, driver):
    self.environment = environment
    self.url = url
    self.driver = driver    // Selenium Driver


def contains_phrase(self, phrase):
    self.driver.get(self.environment.url + self.url_suffix)  // Selenium Command
    ...

此实体现在依赖于 selenium,不再是纯对象(PO​​CO、POJO 等)。在 DDD 中,我觉得这不正确。

我的理解是 selenium 表达式也不属于应用程序服务层,因为这会使 class / 方法膨胀,并且服务层理想情况下应该很薄。

这是否属于基础设施层?就像一个存储库,其中包含持久性代码。类似于:

class PageAutomator:
...
def does_page_contain_phrase(self, page, phrase):
    self.driver.get(self.environment.url + self.url_suffix)  // Selenium Command

这听起来像是正确的方向吗?如果是的话?:

这意味着 Page 实体开始趋向于贫血模型,并正在成为一个简单的 DTO。如果是这样,这个实体还有必要吗?

应用服务层直接调用基础设施层并执行某些操作(执行用例)而完全没有任何实体(以及域)的参与是否可以接受?即使采用更多的事务脚本方法,我的理解是 Selenium 功能仍然不应该存在于域中?

或者(我是 DDD 的新手)我完全偏离了基础,在这种情况下,非常欢迎任何意见或建议。

谢谢

My understanding is that the the selenium expressions also don't belong in the Application Service layer, as this would bloat the class / method and the service layer should ideally be thin.

是的,你是对的。 Selenium 表达式应该保留在基础结构中,因为它们是特定于技术的。

This means the Page entity is starting to tend towards an anaemic model, and is becoming a simple DTO. If so is this entity even necessary any more?

如果域是贫血的(请阅读 'simple'),那么模型也将是贫血的。

当我们考虑应用程序的写入部分时,贫血是有意义的,当行为留在域服务中时,它应该留在聚合内。

If so is this entity even necessary any more?

如果你的东西有一个生命周期(它有一个身份;它被创建、修改然后消亡)那么是的,一个实体是必要的。如果缺少行为(因为域很简单),您可能拥有一个 CRUD 实体,而不是一个成熟的 DDD 聚合。您可以采取其他战略或战术 DDD 决策(如限界上下文和上下文映射)。

Is it acceptable for the Application Service layer to call the Infrastructure layer directly and perform some action (to perform a use case) without the involvement of any entities (and hence the domain) at all?

是的。

在 HTML 中搜索字符串不是业务逻辑,因此领域驱动设计不应适用于此。

没有表示页面行为的 DTO 或 class 在这里是有意义的。

如果需要对 Selenium 特定实现进行抽象或跨应用程序重用,"search service" 将成为基础架构问题。如果不需要,那将是特定于应用程序的 service/utility.