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?
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.
Not necessarily, in my opinion. Since you are using a layered architecture, I assume your DTOs reside in an upper layer -- commonly the service layer - that acts as the communication point between server and clients. Indeed, the main purpose of the DTOs as their name imply (Data Transfer Objects) is to enable for communication, transfering the information without any kind of logic attached - eg. operations.
Layers should only know those located beneath, not above; thus, the DTOs should be kept in the service layer and be consumed by whoever is responsible - for instance, a command processor - in order to retrieve the domain objects from a repository and perform whatever operations are involved.
Bottom line: DTOs don't apply to the domain, they belong to service / communications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With