title: Multiple implementations for one interface with DI
body: <p>Right now I'm trying to teach myself the Dependency Injection pattern with the IOC-container from Autofac. I've come up with a very simple example, which is presented below. Although the example is simple, I fail to get it working properly.</p>
  
  <p>Here are my classes/interfaces:</p>
  
  <p>Two monsters, both implementing the IMonster interface:</p>
  
  <pre><code>interface IMonster
  {
    void IntroduceYourself();
  }
  
  class Vampire : IMonster
  {
    public delegate Vampire Factory(int age);
  
    int mAge; 
  
    public Vampire(int age)
    {
      mAge = age;
    }
  
    public void IntroduceYourself()
    {
      Console.WriteLine("Hi, I'm a " + mAge + " years old vampire!");
    }
  }
  
  class Zombie : IMonster
  {
    public delegate Zombie Factory(string name);
  
    string mName;
  
    public Zombie(string name)
    {
      mName = name;
    }
  
    public void IntroduceYourself()
    {
      Console.WriteLine("Hi, I'm " + mName + " the zombie!");
    }
  }
  </code></pre>
  
  <p>Then there's my graveyard:</p>
  
  <pre><code>interface ILocation
  {
    void PresentLocalCreeps();
  }
  
  class Graveyard : ILocation
  {
    Func&lt;int, IMonster&gt;    mVampireFactory;
    Func&lt;string, IMonster&gt; mZombieFactory;
  
    public Graveyard(Func&lt;int, IMonster&gt; vampireFactory, Func&lt;string, IMonster&gt; zombieFactory)
    {
      mVampireFactory = vampireFactory;
      mZombieFactory  = zombieFactory;
    }
  
    public void PresentLocalCreeps()
    {
      var vampire = mVampireFactory.Invoke(300);
      vampire.IntroduceYourself();
  
      var zombie = mZombieFactory.Invoke("Rob");
      zombie.IntroduceYourself();
    }
  }
  </code></pre>
  
  <p>And finally my main:</p>
  
  <pre><code>static void Main(string[] args)
  {
    // Setup Autofac
    var builder = new ContainerBuilder();
    builder.RegisterType&lt;Graveyard&gt;().As&lt;ILocation&gt;();
    builder.RegisterType&lt;Vampire&gt;().As&lt;IMonster&gt;();
    builder.RegisterType&lt;Zombie&gt;().As&lt;IMonster&gt;();
    var container = builder.Build();
  
    // It's midnight!
    var location = container.Resolve&lt;ILocation&gt;();
    location.PresentLocalCreeps();
  
    // Waiting for dawn to break...
    Console.ReadLine(); 
    container.Dispose();
  }
  </code></pre>
  
  <p>And this is my problem:
  During runtime, Autofac throws an exception on this line:</p>
  
  <pre><code>var vampire = mVampireFactory.Invoke(300);
  </code></pre>
  
  <p>It seems that the mVampireFactory is actually trying to instantiate a zombie. Of course this won't work since the zombie's constructor won't take an int.</p>
  
  <p>Is there a simple way to fix this?
  Or did I get the way Autofac works completely wrong?
  How would you solve this problem?</p>