title: Using MediatR is it possible to create a generic RequestExceptionHandler for any and all requests?
body: <p>I created a request exception handler with known types as below and the exception is handled.  The only examples I found are doing it this way.</p>
  <pre><code>using MediatR.Pipeline;
  using Microsoft.Extensions.Logging;
  using MyPortal.Application.Common.Models;
  using MyPortal.Application.MyCommands.Commands.CompleteMyCommand;
  using System;
  using System.Threading;
  using System.Threading.Tasks;
  
  namespace MyPortal.Application.Common.Behaviors
  {
      public class RequestGenericExceptionHandler : IRequestExceptionHandler&lt;MyCommand, Result&gt;
      {
          private readonly ILogger&lt;MyCommand&gt; _logger;
  
          public RequestGenericExceptionHandler(ILogger&lt;MyCommand&gt; logger)
          {
              _logger = logger;
          }
  
          public async Task Handle(MyCommand request,
              Exception exception,
              RequestExceptionHandlerState&lt;Result&gt; state,
              CancellationToken cancellationToken)
          {
              var name = typeof(MyCommand).Name;
              _logger.LogError(&quot;MyPortal Request Exception {@Request}&quot;,
                      name, exception.Message, request);
          }
      }
  }
  </code></pre>
  <p>When I try to use something like this it's not handled:</p>
  <pre><code>    public class RequestGenericExceptionHandler&lt;TRequest, TResponse&gt; : IRequestExceptionHandler&lt;TRequest, TResponse&gt;
          where TRequest : IRequest&lt;TResponse&gt;
      {
          private readonly ILogger&lt;TRequest&gt; _logger;
  
          public RequestGenericExceptionHandler(ILogger&lt;TRequest&gt; logger)
          {
              _logger = logger;
          }
  
          public async Task Handle(TRequest request,
              Exception exception,
              RequestExceptionHandlerState&lt;TResponse&gt; state,
              CancellationToken cancellationToken)
          {
              var name = typeof(TRequest).Name;
              _logger.LogError(&quot;MyPortal Request Exception {@Request}&quot;,
                      name, exception.Message, request);
          }
      }
  </code></pre>
  <p>I'm using .Net Core 3.1, Mediator 8.0.1, and MediatR.Extensions.Microsoft.DependencyIntjection 8.0.0 and this is my only dependency injection:</p>
  <pre><code>            services.AddMediatR(Assembly.GetExecutingAssembly());
  </code></pre>