title: Response / Request pattern ... How to shape the DTOs?
body: <p>I am using Request/Response pattern on a service layer. I have, for example:</p>
  
  <pre><code>public class FindPostsByTypeRequest : Request {
    public PostType Type { get; set; }
  }
  
  public class FindPostsByTypeResponse : Response {
    public IList&lt;PostDto&gt; Posts { get; set; }
  
    public class PostDto {
      public Int32 Id { get; set; }
      public String Title { get; set; }
      public String Text { get; set; }
    }
  }
  </code></pre>
  
  <p>To handle this request I have an handler:</p>
  
  <pre><code>public class FindPostsByTypeHandler : Handler&lt;FindPostsByTypeRequest, FindPostsByTypeResponse&gt; {
  
    private IContext _context;
  
    public FindPostsByTypeHandler(IContext context) {
      _context = context;
    }
  
    public FindPostsByTypeResponse Handle(FindPostsByTypeRequest request) {
  
      IList&lt;FindPostsByTypeRequest.PostDto&gt; posts = _context.Posts
       .Where(x =&gt; x.Type == request.Type)
       .Select(x =&gt; new FindPostsByTypeRequest.PostDto {
         Id = x.Id,
         Title = x.Title,
         Text = x.Text
       }).ToList();
  
       return new FindPostsByTypeResponse { Posts = posts };
  
    }
  
  }
  </code></pre>
  
  <p>Then I have a dispatcher and use it as follows:</p>
  
  <pre><code>FindPostsByTypeRequest request = new FindPostsByTypeRequest { Type = type };
  
  FindPostsByTypeResponse response = _dispatcher.Send&lt;FindPostsByTypeResponse&gt;(request);
  </code></pre>
  
  <p><strong>The Problem I am trying to solve</strong>:</p>
  
  <p>When I look for posts by type sometimes I need the tags ... Sometimes I don't.
  Of course I could always get the tags into my DTOs and use it or not ...
  But loading something that I do not need should be avoided ...</p>
  
  <p>So basically I need to get the Posts by Type and "tell" the handler what data do I need.</p>
  
  <p>My idea would be something like:</p>
  
  <pre><code>_dispatcher.Send&lt;FindPostsByTypeResponse&lt;PostWithTagsModel&gt;&gt;(request);
  </code></pre>
  
  <p>Where PostWithTagsModel would be the DTO I would need. Then in my Handler I would have:</p>
  
  <pre><code>public class FindPostsByTypeHandler : Handler&lt;FindPostsByTypeRequest, FindPostsByTypeResponse&gt; {
  
    private IContext _context;
  
    public FindPostsByTypeHandler(IContext context) {
      _context = context;
    }
  
    public FindPostsByTypeResponse&lt;PostsByType&gt; Handle(FindPostsByTypeRequest request) {
  
      IList&lt;FindPostsByTypeResponse.PostDto&gt; posts = _context.Posts
       .Where(x =&gt; x.Type == request.Type)
       .Select(x =&gt; new FindPostsByTypeResponse.PostDto {
         Id = x.Id,
         Title = x.Title,
         Text = x.Text
       }).ToList();
  
       return new FindPostsByTypeResponse { Posts = posts };
  
    }
  
    public FindPostsByTypeResponse&lt;PostsWithoutTagsDto&gt; Handle(FindPostsByTypeRequest request) {
  
      IList&lt;FindPostsByTypeResponse.PostsWithoutTagsDto&gt; posts = _context.Posts
       .Where(x =&gt; x.Type == request.Type)
       .Select(x =&gt; new FindPostsByTypeResponse.PostsWithoutTagsDto {
         Id = x.Id,
         Title = x.Title,
         Text = x.Text
       }).ToList();
  
       return new FindPostsByTypeResponse { Posts = posts };
  
    }
  
    public FindPostsByTypeResponse&lt;PostsWithTagsDto&gt; Handle(FindPostsByTypeRequest request) {
      // Remaining code
    }
  
  }
  </code></pre>
  
  <p>I am not sure this is possible or even the best way to do this ...</p>
  
  <p>Basically I need to "tell" the handler in which format I need the DTOs which are included in the Response.</p>
  
  <p>How can I, or should I, do this?</p>