简体   繁体   中英

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. I should use the DTO instead of the entity on the frontend.

My architecture looks like: 在此处输入图片说明

My question is :

Should I use the web module and stick to it in the DTO? Is it the correct approach?

在此处输入图片说明

  • DDD referred mostly to isolated monolithic systems, or at least didn't cover aspects of cross system communication.

Therefore, even if you work "according to DDD", you will have to make your decisions - how to handle these aspects.

Reference: list of patterns introduce in the DDD book, with their relations: 在此处输入图片说明

You should see REST as just one of many "ports" allowing to reach your application layer services. REST, RPC, Websocket, etc. services would adapt & map input to application layer calls and vice-versa. 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.

根据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. Or you could use Builder pattern that accept DTO(s) to create the Domain model. 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.

In your diagram, I am not sure what is the purpose of Application layer. Since what we call application should be the domain models.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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