Search code examples
domain-driven-designimplementationlayerdtoproject-organization

DDD: Should a Dto Assembler be a part of Domain Layer?


Thanks in advance.

I have some Aggregates in the Domain Layer library. Also, some DTOs in a separate library, which is shared between Server and Client side.

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.

Is this right?


Solution

  • 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.

    DTOs (and consequently their assembler) are a technical concept - they define the data structure in the context of a specific interface to your system.

    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.

    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.