开发者

Is using DTO's and Entities breach of DRY principle?

I was looking at a library called Automapper. I am having a few concerns with this:

  1. We dont want to expose our data model (GOOD). Why should the datamodel closely resemble your DB?

  2. using lightweight DTOs instead of your entities. (GOOD)

  3. Now I need开发者_Go百科 to map my entities to these DTOs. Am i respecting the DRY principle??


One could argue that DTOs violate DRY, but if it makes sense for your situation then I wouldn't think twice about it.

DRY, like most programming best practices, isn't a silver bullet. Sometimes you have to compromise. In this case, I'd argue that violating DRY is perfectly acceptable in order to prevent issues that can arise from leaking your domain details to callers that don't need it (e.g. N+1 lazy-loading performance issues).


Depends on the applications. Transaction applications, and depending on the business logic requirements, exposing your data model to upper layer code can make sense for projects of a certain scale. I think DRY becomes important the larger the application, but I don't know enough the context from which you're asking this question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜