2

This code is working fine in .Net5, But when I try to update to .Net 6 there is no Startup.cs class. How should I implement this?

public class Startup
{
  private readonly IConfiguration _config;
  public Startup(IConfiguration config)
  {
    _config = config;
  }
}

Complete Program.cs

using API.Data;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();   
ConfigurationManager config = builder.Configuration;
IConfiguration _config = app.Configuration;


builder.Services.AddDbContext<DataContext>(options =>
{        options.UseSqlServer(_config.GetConnectionString("DefaultConnection"));
});
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();

Using Sql Server 2022, Visual Studio 2022.

Ahsan Khan
  • 51
  • 3

1 Answers1

0

You need to create the web app builder and then you can access the configuration.

var builder = WebApplication.CreateBuilder(args);
// builder.Configuration...

For more info, please read the documentation.

Misha Zaslavsky
  • 8,414
  • 11
  • 70
  • 116