Does DTO and Entities use DRY violation?

I was looking at a library called Automapper . I have a few problems with this:

  • We do not want to disclose our data model (GOOD). Why should data closely resemble your database?

  • using lightweight DTOs instead of your objects. (Good)

  • Now I need to map my objects to these DTOs. Do I respect the DRY principle?

+4
source share
2 answers

It can be argued that DTO violates DRY, but if that makes sense for your situation, then I would not think twice about it.

DRY, like most advanced programming techniques, is not a silver bullet. Sometimes you have to compromise. In this case, I would say that DRY violation is quite acceptable to prevent problems that may occur as a result of leakage of your domain data to callers who do not need it (for example, problems with N + 1 performance for lazy loading).

+4
source

Depends on the application. Transactional applications, and depending on the requirements of business logic, exposing your data model to the upper level of code, may make sense for projects of a certain scale. I think DRY becomes important the bigger the application, but I don’t know enough the context from which you are asking this question.

0
source

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


All Articles