title: Injecting multiple implementations with Dependency injection
body: <p>I'm currently working on a ASP.NET Core Project and want to use the built-in Dependency Injection (DI) functionality.</p>
  
  <p>Well, I started with an interface:</p>
  
  <pre><code>ICar
  {
      string Drive();
  }
  </code></pre>
  
  <p>and want to implement the <code>ICar</code> interface multiple times like</p>
  
  <pre><code>public class BMW : ICar
  {
      public string Drive(){...};
  }
  
  public class Jaguar : ICar
  {
      public string Drive(){...};
  }
  </code></pre>
  
  <p>and add the following in the <code>Startup</code> class</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
       // Add framework services.
       services.AddMvc();
       services.AddTransient&lt;ICar, BMW&gt;(); 
       // or 
       services.AddTransient&lt;ICar, Jaguar&gt;();
   }
  </code></pre>
  
  <p>Now I have to make a decision between two implementations and my decided class will set in every constructor that needs an ICar implementation. <strong>But my idea was to say, if the requested Controller is BMWController, then use BMW implementation or use Jaguar if the JaguarController is requested</strong>. </p>
  
  <p>Otherwise DI don't make sense for me. How can i handle this issue properly?</p>
  
  <p><strong>For better understanding my problem take a look to this pic: <a href="https://media-www-asp.azureedge.net/media/44907/dependency-injection-golf.png?raw=true" rel="noreferrer">https://media-www-asp.azureedge.net/media/44907/dependency-injection-golf.png?raw=true</a>
  How does the dependency resolver work and where can i set it up in ASP.NET Core?</strong></p>
  
  <p>In Unity it's possible to make something like this
      <code>container.RegisterType&lt;IPerson, Male&gt;("Male");</code>
      <code>container.RegisterType&lt;IPerson, Female&gt;("Female");</code></p>
  
  <p>and call the correct type like this </p>
  
  <pre><code>[Dependency("Male")]IPerson malePerson
  </code></pre>