title: Autofac with multiple implementations of the same interface
body: <p>I'm using Autofac and would like to have multiple implementations of an interface. How can I configure Autofac so to resolve dependencies based on the current type?</p>
  
  <p>More specifically, I have one interface and multiple implementations that should be chained together.</p>
  
  <p>Let me explain (fictitious classes):</p>
  
  <pre><code>public interface IMessageHandler
  {
      void Handle(Message message);
  }
  
  public class LoggingMessageHandler : IMessageHandler
  {
      private IMessageHandler _messageHandler;
  
      public LoggingMessageHandler(IMessageHandler messageHandler)
      {
          _messageHandler = messageHandler;
      }
  
      public void Handle(Message message) 
      {
          // log something
          _messageHandler.Handle(message);
      }
  }
  
  public class DoSomethingMessageHandler : IMessageHandler
  {
      private IMessageHandler _messageHandler;
  
      public DoSomethingMessageHandler (IMessageHandler messageHandler)
      {
          _messageHandler = messageHandler;
      }
  
      public void Handle(Message message) 
      {
          // do something
          _messageHandler.Handle(message);
      }
  }
  </code></pre>
  
  <p>At the bottom of the chain might be an <code>IMessageHandler</code> that doesn't pass the message on to the next one.</p>
  
  <p>If I want the following chain:</p>
  
  <pre><code>TopLevelClass -&gt; LoggingMessageHandler -&gt; DoSomethingMessageHandler -&gt; FinalHandler
  </code></pre>
  
  <p>How can I tell Autofac to </p>
  
  <ul>
  <li>pass <code>LoggingMessageHandler</code> to <code>TopLevelClass</code> (to fulfill its dependency on <code>IMessageHandler</code>)</li>
  <li>pass <code>DoSomethingMessageHandler</code> to <code>LoggingMessageHandler</code> (to fulfill its dependency on <code>IMessageHandler</code>)</li>
  <li>pass <code>LoggingMessageHandler</code> to <code>FinalHandler</code> (to fulfill its dependency on <code>IMessageHandler</code>)</li>
  </ul>
  
  <p>Is it even possible (I have read about the <a href="https://code.google.com/p/autofac/wiki/RelationshipTypes#Example%3a_Implicit_IEnumerable_Support">implicit support for IEnumerable</a>)? Or will I have to use an extra class in between (a factory or something)?</p>