title: How can "IConfiguration object is registered with DI by default" in Startup.cs in .NET Core 2
body: <p>In, aspnet core 2, when we want to to Access configuration during startup, we can do it thanks to dependency injection as far as I understood.</p>
  
  <p>For this code in below, how can we pass <code>IConfiguration</code> object to this class with benefits of Dependency Injection ;</p>
  
  <pre><code>public class Startup
  {
      public Startup(IConfiguration configuration)
      {
          Configuration = configuration;
      }
  
      public IConfiguration Configuration { get; }
  
      public void ConfigureServices(IServiceCollection services)
      {
          services.AddMvc();
      }
  
      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
          else
          {
              app.UseExceptionHandler("/Home/Error");
          }
  
          app.UseStaticFiles();
  
          app.UseMvc(routes =&gt;
          {
              routes.MapRoute(
                  name: "default",
                  template: "{controller=Home}/{action=Index}/{id?}");
          });
      }
  }
  </code></pre>
  
  <p>I saw a sentence:</p>
  
  <p><strong><em>" The IConfiguration object is registered with DI by default."</em></strong></p>
  
  <p>How can we succeed this?</p>
  
  <p>In <em>program.cs</em> there is a code like this, do we set <code>IConfiguration</code> object in <em>startup.cs</em> class with this code below? I thought .UseStartup()
  code carries out this job(passing IConfiguration object to Startup class)  for us. But how?</p>
  
  <pre><code>public class Program
  {
      public static void Main(string[] args)
      {
          CreateWebHostBuilder(args).Build().Run();
      }
  
      public static IWebHostBuilder CreateWebHostBuilder(string[] args) =&gt;
          WebHost.CreateDefaultBuilder(args)
          .ConfigureAppConfiguration(SetupConfiguration)
            .UseStartup&lt;Startup&gt;();
  
      private static void SetupConfiguration(WebHostBuilderContext ctx, IConfigurationBuilder builder)
      {
          //Remove the default configuration options
          builder.Sources.Clear();
  
          builder.AddJsonFile("config.json", false, true).
              AddEnvironmentVariables();
      }
  }
  </code></pre>
  
  <p>I would be so happy if someone can explain this with deep details.</p>