title: ASP.NET Core MVC Dependency Injection issue
body: <p>I'm relatively new to ASP.NET Core MVC and am running into issues with dependency injection.</p>
  
  <p>I have a solution with multiple projects in which I want to share a EF database context class. I have defined an interface for a configuration manager so I can share common config across projects, but have project specific config as well.</p>
  
  <p>When running the various API's dependency injection fails with a </p>
  
  <blockquote>
    <p>"System.InvalidOperationException: Unable to resolve service for type
    IConfigManager"</p>
  </blockquote>
  
  <p>error.</p>
  
  <blockquote>
    <p>Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddl‌​eware[0]
    An unhandled exception has occurred while executing the request
    System.InvalidOperationException: Unable to resolve service for type
    'NovaSec.Core.IConfigManager' while attempting to activate
    'NovaSec.Core.Contexts.CustomDbContext'. at
    Microsoft.Extensions.DependencyInjection.ServiceLookup.Servi‌​ce.PopulateCallSites‌​(ServiceProvider
    provider, ISet`1 callSiteChain, ParameterInfo[] parameters, Boolean
    throwIfCallSiteNotFound)</p>
  </blockquote>
  
  <p>The <code>DBContextClass</code> is part of a class library project I reference in the other projects.</p>
  
  <p>I have no idea why it does not work. Can someone please help and explain this to me?</p>
  
  <p><strong>DBContext Class</strong></p>
  
  <pre><code>   public class CustomDbContext : IdentityDbContext&lt;CustomIdentity, CustomRole, string&gt;
      {
          public CustomDbContext(DbContextOptions&lt;CustomDbContext&gt; options, IConfigManager configManager) : base(options)
          {
              var optionsBuilder = new DbContextOptionsBuilder&lt;CustomDbContext&gt;();
              optionsBuilder.UseSqlite(configManager._config.ConnectionStrings.FirstOrDefault(c =&gt; c.id == "IdentityDatabase").connectionString);
          }
      }
  </code></pre>
  
  <p><strong>Config Manager interface and implementation class</strong></p>
  
  <pre><code>public interface IConfigManager
  {
      IAppConfig _config { get; set; }
  }
  
  public class ConfigManager : IConfigManager
  {
      public IAppConfig _config { get; set; }
      public ConfigManager(IAppConfig config)
      {
  
      }
  }
  </code></pre>
  
  <p><strong>Startup Method</strong></p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddSingleton&lt;IConfigManager, ConfigManager&gt;(config =&gt;
      {
          return new ConfigManager(_config);
      });
      IServiceProvider serviceProvider = services.BuildServiceProvider();
      _configManager = (ConfigManager)serviceProvider.GetService&lt;IConfigManager&gt;();
      services.AddDbContext&lt;CustomDbContext&gt;();
      services.AddIdentity&lt;CustomIdentity, CustomRole&gt;(config =&gt; {
          config.SignIn.RequireConfirmedEmail = true;
      })
          .AddEntityFrameworkStores&lt;CustomDbContext&gt;()
          .AddDefaultTokenProviders();
      services.AddIdentityServer()
      .AddInMemoryClients(_configManager.GetClients())
      .AddInMemoryIdentityResources(_configManager.GetIdentityResources())
      .AddInMemoryApiResources(_configManager.GetApiResources())
      .AddTemporarySigningCredential()
      .AddAspNetIdentity&lt;CustomIdentity&gt;();
  
  }
  </code></pre>