DDD:Dto汇编程序是否应该是域层的一部分? [英] DDD: Should a Dto Assembler be a part of Domain Layer?
问题描述
先谢谢了.
我在 Domain Layer 库中有一些 Aggregates .另外,一些 DTO 位于单独的库中,在 Server 和 Client 端之间共享.
I have some Aggregates in the Domain Layer library. Also, some DTOs in a separate library, which is shared between Server and Client side.
实体的聚合比其 DTO 更具信息性.因此,为了从 DTO 转换为 Aggregate ,存储库应该由 Dto汇编器访问. 存储库的接口位于域层中.这就是为什么我得出结论: DtoAssembler 应该是 DomainLayer 的一部分的原因.
An Aggregate of an entity is more informative than its DTO. So, in order to convert from DTO to Aggregate, a repository should be accessed by a Dto Assembler. Interfaces of repositories are in Domain Layer. That's why i come to conclusion that DtoAssembler should be a part of DomainLayer.
这是对的吗
推荐答案
不,在DDD的上下文中,这将是完全错误的.
尝试询问(非技术)领域专家对DTO汇编器的看法.他将以怀疑的大眼睛望着你.
No, this would be plain wrong in the context of DDD.
Try asking a (non-technical) domain expert what he thinks about the DTO assembler. He will look with large, questioning eyes at you.
DTO(以及因此的汇编程序)是一个技术概念-它们在与系统特定接口的上下文中定义数据结构.
存储库大多返回聚合.如果您在数据库中查询未在您的域中建模的统计数据,则存储库也可能返回不可变的数据对象.只要确保您在执行此操作时不会意外遗漏域概念即可.
Repositories mostly return aggregates. If you query the database for statistical data that is not modeled in your domain, then a repository may also return an immutable data object. Just make sure that you're not accidentally missing a domain concept when doing that.
一旦您从存储库中获得了数据(无论它是聚合对象还是数据对象),您都可以将其输入DTO汇编器中.
Once you have the data from a repository (no matter whether it is an aggregate or a data object) you can feed it into the DTO assembler.
这篇关于DDD:Dto汇编程序是否应该是域层的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!