I have created the Rest Api's in .Net 5 and everything was working perfectly but recently I've been moved to .NET 6 and there I've realized that no startup.cs class is present and another thing is how to add the DB Context?
I have created the Rest Api's in .Net 5 and everything was working perfectly but recently I've been moved to .NET 6 and there I've realized that no startup.cs class is present and another thing is how to add the DB Context?
In .NET 6 Microsoft has removed the Startup.cs class. Just go to the program.cs file and there you can add a connection string then you've to use builder.Services.AddDbContext
The old way is
services.AddDbContext
Just use
builder.Services
and then you can achieve what you want.
In .NET 6, they unified Startup.cs and Program.cs into Program.cs.
Now registering middleware, services, authentication and adding DbContext and everything else into the Program.cs file.
Here is an example of a Program.cs file:
var builder = WebApplication.CreateBuilder(args);
//Register services here
//Register middleware here
//builder.Services.AddAuthentication(...)
//app.UseAuthentication();
app.MapGet("/", () => "Hello World!");
app.Run();
For more information visit this thread.