简体   繁体   English

域驱动设计:DTO在哪里?

[英]Domain-Driven Design: where are the DTO?

I have a problem with the domain-driven design architecture. 我对域驱动的设计体系有疑问。 Everything looks nice until I try to use REST. 在尝试使用REST之前,一切看起来都很不错。 I should use the DTO instead of the entity on the frontend. 我应该使用DTO而不是前端上的实体。

My architecture looks like: 我的架构如下: 在此处输入图片说明

My question is : 我的问题是:

Should I use the web module and stick to it in the DTO? 我是否应该使用Web模块并坚持使用DTO? Is it the correct approach? 这是正确的方法吗?

在此处输入图片说明

  • DDD referred mostly to isolated monolithic systems, or at least didn't cover aspects of cross system communication. DDD主要指隔离的单片系统,或者至少不涉及跨系统通信的各个方面。

Therefore, even if you work "according to DDD", you will have to make your decisions - how to handle these aspects. 因此,即使您“按照DDD”工作,也必须做出决定-如何处理这些方面。

Reference: list of patterns introduce in the DDD book, with their relations: 参考:DDD书中介绍的模式列表及其关系: 在此处输入图片说明

You should see REST as just one of many "ports" allowing to reach your application layer services. 您应该将REST视为允许访问应用程序层服务的众多“端口”之一。 REST, RPC, Websocket, etc. services would adapt & map input to application layer calls and vice-versa. REST,RPC,Websocket等服务将调整输入并将其映射到应用程序层调用,反之亦然。 At each service boundary you still have the flexibility to adapt responses, which does not have to have a 1-1 mapping with application service method responses, but could. 在每个服务边界,您仍然可以灵活地调整响应,而不必与应用程序服务方法响应进行1-1映射,但是可以。

根据Vaughn Vernon的《实现域驱动设计》一书,DTO位于应用层中。

Ideally, the Domain models should be created by factories. 理想情况下,域模型应该由工厂创建。 So the factories can accept DTO and return an instance of the Domain model. 因此工厂可以接受DTO并返回Domain模型的实例。 Or you could use Builder pattern that accept DTO(s) to create the Domain model. 或者,您可以使用接受DTO的Builder模式来创建Domain模型。 This way you're domain model is kept clean from DTO and the Application layer in your architecture diagram should accept DTO(s) as parameters. 这样,您的域模型就不会受到DTO的影响,并且体系结构图中的Application层应接受DTO作为参数。

In your diagram, I am not sure what is the purpose of Application layer. 在您的图中,我不确定应用程序层的目的是什么。 Since what we call application should be the domain models. 因为我们所谓的应用程序应该是领域模型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM