title: Autofac generic decorator not fired (with mediatr)
body: <p>I have trouble with my generic decorator and can not find a solution on any topic I have looked. I Think I'm close but I miss something.</p>
  <p>To simplify, I have an API in .NetCore and a module in .Net Standard. I want to manage the DI for the module in the .Net Standard and the API just call it in Startup.</p>
  <p>In Program.cs, I use the autofac service provider factory</p>
  <pre class="lang-cs prettyprint-override"><code>public static IHostBuilder CreateHostBuilder(string[] args)
  {
      return Host.CreateDefaultBuilder(args)
          .ConfigureWebHostDefaults(webBuilder =&gt; webBuilder
              .UseStartup&lt;Startup&gt;()
              .UseSerilog()
          )
          .UseServiceProviderFactory(new AutofacServiceProviderFactory());
  }
  </code></pre>
  <p>In my Startup.cs, I have the ConfigureContainer who initialize my modules</p>
  <pre class="lang-cs prettyprint-override"><code>public void ConfigureContainer(ContainerBuilder builder)
  {
      builder.RegisterModule(new MyModuleAutofacModule());
  
      MyModuleStartup.Initialize();
  }
  </code></pre>
  <p>In my module startup, I register my submodules, types, ...</p>
  <pre class="lang-cs prettyprint-override"><code>public static void Initialize()
  {
      var containerBuilder = new ContainerBuilder();
  
      containerBuilder.AddMediatR(typeof(StudiDropboxModule).Assembly);
      containerBuilder.RegisterModule(new ProcessingModule());
      ...
      
      containerBuilder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
          .Where(t =&gt; t.Name.EndsWith(&quot;Handler&quot;))
          .AsImplementedInterfaces();
  
      containerBuilder.RegisterGenericDecorator(
          typeof(LoggingCommandHandlerDecorator&lt;&gt;),
          typeof(ICommandHandler&lt;&gt;));
  }
  </code></pre>
  <p>Command/Command handler inherit from Mediatr</p>
  <pre class="lang-cs prettyprint-override"><code>public interface ICommand : IRequest
  {
  }
  
  public interface ICommandHandler&lt;in TCommand&gt; : IRequestHandler&lt;TCommand&gt; where TCommand : ICommand
  {
  }
  </code></pre>
  <p>My Command/CommandHandler</p>
  <pre class="lang-cs prettyprint-override"><code>public class ExampleCommand : ICommand
  {
      ...
  }
  
  internal class ExampleCommandHandler : ICommandHandler&lt;ExampleCommand&gt;
  {
      public async Task&lt;Unit&gt; Handle(ExampleCommand request, CancellationToken cancellationToken)
      {
          ...
  
          return Unit.Value;
      }
  }
  </code></pre>
  <p>The decorator</p>
  <pre class="lang-cs prettyprint-override"><code>internal class LoggingCommandHandlerDecorator&lt;T&gt; : ICommandHandler&lt;T&gt; where T : ICommand
  {
      private readonly ICommandHandler&lt;T&gt; _decorated;
  
      public LoggingCommandHandlerDecorator(ICommandHandler&lt;T&gt; decorated)
      {
          _decorated = decorated;
      }
  
      public async Task&lt;Unit&gt; Handle(T command, CancellationToken cancellationToken)
      {
          var result = await _decorated.Handle(command, cancellationToken);
  
          return result;
      }
  }
  </code></pre>
  <p>When I call my command with mediatr, the decorator is not fired.</p>
  <p>Mediatr is resolved when I call a command</p>
  <pre class="lang-cs prettyprint-override"><code>internal static async Task Execute(ICommand command)
  {
      using (var scope = MyModuleCompositionRoot.BeginLifetimeScope())
      {
          var mediator = scope.Resolve&lt;IMediator&gt;();
          await mediator.Send(command);
      }
  }
  </code></pre>
  <p>I think I miss something with autofac.</p>
  <p>Thanks in advance.</p>