DDD: Should D-Assembler be part of a domain level?

Thanks in advance.

I have some aggregates in a domain level library. In addition, some DTOs are in a separate library that is shared between the server and the client side.

The totality of an object is more informative than its DTO. So, in order to convert from DTO to Aggregate, a Dat Assembler must be connected to the repository. Repository interfaces are in the domain layer. That's why I came to the conclusion that DtoAssembler should be part of DomainLayer.

Is it correct?

+5
source share
2 answers

No, that would be wrong in the context of DDD.

Try asking a (non-technical) area expert what he thinks about DTO assembler. He will look at you with big, questioning eyes.

DTOs (and therefore 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 a database for statistics that are not modeled in your domain, then the repository can also return an immutable data object. Just make sure that you do not accidentally understand the concept of a domain at the same time.

Once you have data from the repository (regardless of whether it is an aggregate or a data object), you can send it to the DTO assembler.

+7
source

Not necessarily, in my opinion. Since you are using a tiered architecture, I assume that your DTOs are at the top level, usually at the service level, which acts as a point of communication between the server and clients. In fact, the main purpose of the DTO as their name implies (Data Transfer Objects) is to enable communication by transmitting information without reference to any logic - for example. operations.

Layers should know only those that are lower and not higher; therefore, DTOs must be stored at the service level and consumed by those responsible - for example, the shell - to retrieve domain objects from the repository and perform any operations.

Bottom line: DTOs do not apply to the domain, they belong to the service / connection.

+1
source

Source: https://habr.com/ru/post/1236712/


All Articles