title: Autofac resolves multiple instances of the same type
body: <p>I have a slightly modified version of <a href="https://github.com/jbogard/MediatR" rel="nofollow">Mediatr</a> handing command processing in my application. I have implemented a MediatorPipeline that allows me to have pre and post processors.</p>
  
  <pre><code>public class AsyncMediatorPipeline&lt;TRequest, TResponse&gt; 
      : IAsyncRequestHandler&lt;TRequest, TResponse&gt; 
      where TRequest : IAsyncRequest&lt;TResponse&gt;
  {
      private readonly IAsyncRequestHandler&lt;TRequest, TResponse&gt; inner;
      private readonly IAsyncPreRequestHandler&lt;TRequest&gt;[] preRequestHandlers;
      private readonly IAsyncPostRequestHandler&lt;TRequest,TResponse&gt;[] postRequestHandlers;
  
      public AsyncMediatorPipeline(IAsyncRequestHandler&lt;TRequest, TResponse&gt; inner, 
          IAsyncPreRequestHandler&lt;TRequest&gt;[] preRequestHandlers, 
          IAsyncPostRequestHandler&lt;TRequest, TResponse&gt;[] postRequestHandlers)
      {
          this.inner = inner;
          this.preRequestHandlers = preRequestHandlers;
          this.postRequestHandlers = postRequestHandlers;
      }
  
      public async Task&lt;TResponse&gt; Handle(TRequest message)
      {
          foreach (var preRequestHandler in preRequestHandlers)
          {
              await preRequestHandler.Handle(message);
          }
  
          var result = await inner.Handle(message);
  
          foreach (var postRequestHandler in postRequestHandlers)
          {
              await postRequestHandler.Handle(message, result);
          }
  
          return result;
      }
  }
  </code></pre>
  
  <p>I am registering my pre-processors with autofac like so:</p>
  
  <pre><code>builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
      .As(type =&gt; type.GetInterfaces()
          .Where(type =&gt; type.IsClosedTypeOf(typeof(IAsyncPreRequestHandler&lt;&gt;))))
      .InstancePerLifetimeScope();
  </code></pre>
  
  <p>At runtime I am getting duplicate preprcessors. I have to filter the set removing duplicates. I am not sure why this is happening. If i comment out the registration, I do not get any preprocessors, which indicates that I am not duplicating the registration somewhere else.</p>
  
  <p><em>Update:</em> Here are some more details on the type that appears to be getting registered twice. The various class definitions:</p>
  
  <p>The concrete handler</p>
  
  <pre><code>public class ClientEditorFormIdentifierValidationHandler 
  : IAsyncPreRequestHandler&lt;AddOrEditClientCommand&gt;{}
  </code></pre>
  
  <p>The command class</p>
  
  <pre><code>public class AddOrEditClientCommand 
  : IAsyncRequest&lt;ICommandResult&gt;{}
  </code></pre>
  
  <p>The command interface</p>
  
  <pre><code>public interface IAsyncRequest&lt;out TResponse&gt; { }
  </code></pre>