title: Multiple Implementations of IHostedService
body: <p>I'm trying to create background services using IHostedService. Everything works fine if I only have ONE background service. When I try to create more than one implementation of <code>IHostedService</code> only the one that was registered first actually runs.</p>
  
  <pre><code>services.AddSingleton&lt;IHostedService, HostedServiceOne&gt;();
  services.AddSingleton&lt;IHostedService, HostedServiceTwo&gt;();
  </code></pre>
  
  <p>In the above sample <code>StartAsync</code> on <code>HostedServiceOne</code> gets called but <code>StartAsync</code> on <code>HostedServiceTwo</code> never gets called. If I swap the order of registering the two implementations of <code>IHostedService</code> (put <code>IHostedServiceTwo</code> before <code>IHostedServiceOne</code>) then <code>StartAsync</code> on <code>HostedServiceTwo</code> gets called but never for <code>HostedServiceOne</code>.</p>
  
  <p>EDIT:</p>
  
  <p>I was directed to the following: </p>
  
  <p><a href="https://stackoverflow.com/questions/39174989/how-to-register-multiple-implementations-of-the-same-interface-in-asp-net-core">How to register multiple implementations of the same interface in Asp.Net Core?</a></p>
  
  <p>However this isn't for <code>IHostedService</code>. To use the suggested approach I would have to make a call to <code>serviceProvider.GetServices&lt;IService&gt;();</code> but it seems that <code>IHostedService.StartAsync</code> seems to be called internally. I'm not even sure where I would call that to trigger <code>IHostedService.StartAsync</code>.</p>