title: Should the repository layer return data-transfer-objects (DTO)?
body: <p>I have a repository layer that is responsible for my data-access, which is called by a service layer. The service layer returns DTOs which are serialized and sent over the wire. More often than not, services do little more than access a repository and return whatever the repository returns. </p>
  
  <p>But for that to work, the repository has to return an instance of that DTO. Otherwise, you would first have to map the data layer object that the repository returns to a DTO in the service layer and return that. That just seems wasteful. </p>
  
  <p>On top of that, if creation of the DTOs happens in the service layer, something that might have been done before in one repository call and thus one database query, now has to happen with multiple repository calls in the service layer to 'compose' the final DTO. Unless of course I create a transport object for between the data and service layer that can contain such a composed object. Which <em>then</em> has to be mapped to a DTO. It just seems wasteful for the sake of purity. But it also feels wrong to have the repository layer return objects that just exist to be sent over the wire. </p>