title: Dependency Injection - use with Data Transfer Objects (DTOs)?
body: <p>Consider the code below (which has been simplified). I have a service class that returns a list of specific DTO objects that each implement their own specific interface. In the actual code these are getting populated by iterating thru a Dataset as I'm working with legacy code. </p>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li><p>How do we create/use a DTO without newing them up or using the Service Locator anti-pattern? It doesn't make much sense to compose an empty DTO object in the Composition Root and inject it into the Service class via the constructor, because I'd actually be using the DTO as a temporary variable of sorts while populating a list.</p></li>
  <li><p>In the code you can see an example of me newing up the DTO. But this doesn't feel much 
  better than if I made the DTOs not implement interfaces in the first place. So should they not implement interfaces then and thus, not use DI with DTOs?</p></li>
  </ol>
  
  <hr>
  
  <pre><code>public class Services : IServices
  {    
      public IList&lt;IDTO&gt; GetDTOs()
      {    
          ...
          List&lt;IDTO&gt; dtos = new List&lt;IDTO&gt;();
          foreach (c in d) 
          {
              DTO dto = new DTO();
              dto.x = c.x;
              dto.y = c.y;
              dto.z = c.z;
              dtos.Add(dto);
          }
          return dtos;
      }    
  }
  </code></pre>