title: Add validation to a MediatR behavior pipeline?
body: <p>I'm using ASP.NET Core, the built-in container, and MediatR 3 which supports <a href="http://github.com/jbogard/MediatR/wiki/Behaviors" rel="noreferrer">"behavior" pipelines</a>:</p>
  
  <pre><code>public class MyRequest : IRequest&lt;string&gt;
  {
      // ...
  }
  
  public class MyRequestHandler : IRequestHandler&lt;MyRequest, string&gt;
  {
      public string Handle(MyRequest message)
      {
          return "Hello!";
      }
  }
  
  public class MyPipeline&lt;TRequest, TResponse&gt; : IPipelineBehavior&lt;TRequest, TResponse&gt;
  {
      public async Task&lt;TResponse&gt; Handle(TRequest request, RequestHandlerDelegate&lt;TResponse&gt; next)
      {
          var response = await next();
          return response;
      }
  }
  
  // in `Startup.ConfigureServices()`:
  services.AddTransient(typeof(IPipelineBehavior&lt;MyRequest,str‌​ing&gt;), typeof(MyPipeline&lt;MyRequest,string&gt;))
  </code></pre>
  
  <p>I need a FluentValidation validator in the pipeline. In MediatR 2, a <a href="http://lostechies.com/jimmybogard/2016/10/13/mediatr-pipeline-examples/" rel="noreferrer">validation pipeline was created thus</a>:</p>
  
  <pre><code>public class ValidationPipeline&lt;TRequest, TResponse&gt;
      : IRequestHandler&lt;TRequest, TResponse&gt;
      where TRequest : IRequest&lt;TResponse&gt;
  {
  
      public ValidationPipeline(IRequestHandler&lt;TRequest, TResponse&gt; inner, IEnumerable&lt;IValidator&lt;TRequest&gt;&gt; validators)
      {
          _inner = inner;
          _validators = validators;
      }
  
      public TResponse Handle(TRequest message)
      {
          var failures = _validators
              .Select(v =&gt; v.Validate(message))
              .SelectMany(result =&gt; result.Errors)
              .Where(f =&gt; f != null)
              .ToList();
          if (failures.Any())
              throw new ValidationException(failures);
          return _inner.Handle(request);
      }
  
  }
  </code></pre>
  
  <p>How do I do that now for the new version? How do I set which validator to use?</p>