title: Dependency Injection with Simple Injector and .Net Core
body: <p>I am running into an error 'Unable to resolve service for type 'MassTransit.IBusControl' while attempting to activate 'PCNDmzWeb.Api.Services.MassTransitHostedService'.'"</p>
  
  <p>I am using the boilerplate code for MVC Core with a few minor changes. In the Configure services method i have the following:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddMvc();
  
      _container.RegisterInstance&lt;IBusControl&gt;(
          Bus.Factory.CreateUsingRabbitMq(sbc =&gt;
          {
              var host = sbc.Host("localhost", "dev", h =&gt;
              {
                  h.Username("guest");
                  h.Password("guest");
              });
              sbc.ReceiveEndpoint(host, "job_results_queue", e =&gt;
              {
                  e.Consumer&lt;StoreJobResultsConsumer&gt;();
              });
          }));
  
      services.AddScoped&lt;IHostedService, MassTransitHostedService&gt;();
  
      IntegrateSimpleInjector(services);
  }
  </code></pre>
  
  <p>It does not appear that the instance of the BusControl is getting created.
   The message seems to indicate that the error is occurring in the Microsoft Extensions Dependency Injection. What am I doing wrong?</p>
  
  <p>Stack Trace follows:</p>
  
  <blockquote>
    <p>Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type
    serviceType, Type implementationType, ISet<code>1 callSiteChain,
    ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound) at
    Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(Type
    serviceType, Type implementationType, ISet</code>1 callSiteChain) at
    Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor
    descriptor, Type serviceType, ISet<code>1 callSiteChain) at
    Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateEnumerable(Type
    serviceType, ISet</code>1 callSiteChain) at
    Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type
    serviceType, ISet<code>1 callSiteChain) at
    Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type
    serviceType, Type implementationType, ISet</code>1 callSiteChain,
    ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound) at
    Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(Type
    serviceType, Type implementationType, ISet<code>1 callSiteChain) at
    Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor
    descriptor, Type serviceType, ISet</code>1 callSiteChain) at
    Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Type
    serviceType, ISet<code>1 callSiteChain) at
    Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type
    serviceType, ISet</code>1 callSiteChain) at
    Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type
    serviceType, ServiceProvider serviceProvider) at
    System.Collections.Concurrent.ConcurrentDictionaryExtensions.GetOrAdd[TKey,TValue,TArg](ConcurrentDictionary<code>2
    dictionary, TKey key, Func</code>3 valueFactory, TArg arg) at
    Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type
    serviceType) at
    Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider
    provider, Type serviceType) at
    Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider
    provider) at
    Microsoft.AspNetCore.Hosting.Internal.WebHost.d__26.MoveNext()
    --- End of stack trace from previous location where exception was thrown --- at
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task) at
    Microsoft.AspNetCore.Hosting.WebHostExtensions.d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown --- at
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task) at
    Microsoft.AspNetCore.Hosting.WebHostExtensions.d__4.MoveNext()
    --- End of stack trace from previous location where exception was thrown --- at
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task) at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost
    host) at PCNDmzWeb.Api.Program.Main(String[] args) in
    C:\myapp\PCNDmzWeb.Api\Program.cs:line 17</p>
  </blockquote>