title: .net core injecting and resolving services
body: <p>I am trying my hand at .net core web api. I have created a static method for registering my controllers like this:</p>
  
  <pre><code>public static class RegistrationExtensions
  {
      public static void RegisterApplicationServices(this IServiceCollection services, IServiceProvider serviceProvider)
      {
          services.RegisterSingletons();
          services.RegisterRequests();
          services.RegisterTransient(serviceProvider);
      }
  
      public static void RegisterSingletons(this IServiceCollection services)
      {
          services.AddSingleton&lt;Configuration&gt;();
      }
  
      public static void RegisterRequests(this IServiceCollection services)
      {
          services.AddScoped&lt;ISettingsService, SettingsService&gt;();
      }
  
      public static void RegisterTransient(this IServiceCollection services, IServiceProvider serviceProvider)
      {
          var config = serviceProvider.GetService&lt;Configuration&gt;();
          services.AddDbContext&lt;InteractiveChoicesContext&gt;(m =&gt; m.UseSqlServer(config.ConnectionString));
      }
  }
  </code></pre>
  
  <p>As you can see, I want to resolve my <strong>Configuration</strong> class which contains my <strong>ConnectionString</strong>, which I pass into the <strong>DbContext</strong>.
  Do resolve the <strong>Configuration</strong> I was trying to use <strong>IServiceProvider</strong> which is injected into the <strong>RegisterApplicationServices</strong> method.</p>
  
  <p>To invoke this method, I changed the <strong>Startup</strong> class's <strong>ConfigureServices</strong> to this:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services, IServiceProvider serviceProvider)
  {
      services.AddMvc();
      services.RegisterApplicationServices(serviceProvider);
  }
  </code></pre>
  
  <p>But when I run my application, I get an error:</p>
  
  <blockquote>
    <p>The ConfigureServices method must either be parameterless or take only one parameter of type IServiceCollection.</p>
  </blockquote>
  
  <p>The error is obvious. My question is: How can I resolve the <strong>Configuration</strong> class in my <strong>RegisterTransient</strong> method?</p>