I am learning about DDD and I would like to say what is the correct way to implement DTO using DDD principles ?
In my onion architecture I implement a first DTO definition in presentation layer to map datas between RabbitMQViewModel(presentation layer) and RabbitMQModelsResultDTO (application layer).
And I implement a second DTO definition between application layer (RabbitMQModelsResultDTO) and domain layer (entity LogRabbitMQ).
However, I am not sure if it's a good way to implement two DTO definition ?
Light description of my DTO definition in presentation layer :
CreateMap<RabbitMQViewModel, RabbitMQModelsResultDTO>().ReverseMap();
and application layer :
CreateMap<Domain.Entities.LogRabbitMQ, RabbitMQModelsDTO>().ReverseMap();
It's a screen of my project architecture :
Translating presentation object (RabbitMQViewModel
) into application object (RabbitMQModelsResultDTO
) then application object into domain object (LogRabbitMQ
) is considered to be a good practice in the DDD world.
However, it is pointless to make anemic, flat translations: it would be much easier to use the same object through all three layers (in which case DDD becomes irrelevant).
Here is how it can be done in the DDD way:
As for the term "DTO", it should be used primarily for presentation object. It is less appropriate to use it in the context of application/domain objects, which are considered to be business objects.