views:

119

answers:

2

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 to map my entities to these DTOs. Am i respecting the DRY principle??

+3  A: 

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).

Kevin Pang
A: 

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.

cbkadel