title: ASP.NET Core 6 how to access Configuration during startup
body: <p>In earlier versions, we had Startup.cs class and we get configuration object as follows in the <strong>Startup</strong> file.</p>
  <pre class="lang-cs prettyprint-override"><code>public class Startup 
  {
      private readonly IHostEnvironment environment;
      private readonly IConfiguration config;
  
      public Startup(IConfiguration configuration, IHostEnvironment environment) 
      {
          this.config = configuration;
          this.environment = environment;
      }
  
      public void ConfigureServices(IServiceCollection services) 
      {
          // Add Services
      }
  
      public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 
      {
          // Add Middlewares
      }
  
  }
  </code></pre>
  <hr />
  <p>Now in .NET 6 (With Visual Studio 2022), we don't see the <strong>Startup.cs</strong> class. Looks like its days are numbered. So how do we get these objects like Configuration(IConfiguration) and Hosting Environment(IHostEnvironment)</p>
  <p>How do we get these objects, to say read the configuration from appsettings? Currently the Program.cs file looks like this.</p>
  <pre class="lang-cs prettyprint-override"><code>using Festify.Database;
  using Microsoft.EntityFrameworkCore;
  
  var builder = WebApplication.CreateBuilder(args);
  
  // Add services to the container.
  builder.Services.AddRazorPages();
  
  builder.Services.AddDbContext&lt;FestifyContext&gt;();
  
  
  ////////////////////////////////////////////////
  // The following is Giving me error as Configuration 
  // object is not avaible, I dont know how to inject this here.
  ////////////////////////////////////////////////
  
  
  builder.Services.AddDbContext&lt;FestifyContext&gt;(opt =&gt;
          opt.UseSqlServer(
              Configuration.GetConnectionString(&quot;Festify&quot;)));
  
  
  var app = builder.Build();
  
  // Configure the HTTP request pipeline.
  if (!app.Environment.IsDevelopment())
  {
      app.UseExceptionHandler(&quot;/Error&quot;);
      // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
      app.UseHsts();
  }
  
  app.UseHttpsRedirection();
  app.UseStaticFiles();
  
  app.UseRouting();
  
  app.UseAuthorization();
  
  app.MapRazorPages();
  
  app.Run();
  </code></pre>
  <p>I want to know how to read the configuration from appsettings.json ?</p>