title: Dependency injection of multiple instances of same type in ASP.NET Core 2
body: <p>In ASP.NET Core 2 Web Api, I want to use dependency injection to inject <code>httpClientA</code> instance of <code>HttpClient</code> to <code>ControllerA</code>, and an instance <code>httpClientB</code> of the <code>HttpClient</code> to <code>ControllerB</code>.</p>
  
  <p>The DI registration code would look something like:</p>
  
  <pre><code>HttpClient httpClientA = new HttpClient();
  httpClientA.BaseAddress = endPointA;
  services.AddSingleton&lt;HttpClient&gt;(httpClientA);
  
  HttpClient httpClientB = new HttpClient();
  httpClientB.BaseAddress = endPointB;
  services.AddSingleton&lt;HttpClient&gt;(httpClientB);
  </code></pre>
  
  <p>I know I could subclass <code>HttpClient</code> to make a unique type for each controller, but that doesn't scale very well.</p>
  
  <p>What is a better way?</p>
  
  <p><strong>UPDATE</strong>
  Specifically regarding HttpClient Microsoft seems to have something in the works </p>
  
  <p><a href="https://github.com/aspnet/HttpClientFactory/blob/dev/samples/HttpClientFactorySample/Program.cs#L32" rel="noreferrer">https://github.com/aspnet/HttpClientFactory/blob/dev/samples/HttpClientFactorySample/Program.cs#L32</a> - thanks to @mountain-traveller (Dylan) for pointing this out.</p>