Before ASP.NET Core 6, registering MVC services was done in the startup class. But right now there is no startup class in the current ASP.NET Core empty project.
In the startup class, it was done in the ConfigureServices
method using AddMvc()
and the MVC middleware, UseMvcWithDefaultRoute()
was added in the Configure
method.
How do I implement this without the startup class?
Tried searching online, but it seems most blog posts and youtube videos were made before the removal of the startup class. And couldn't find the specific docs either.
Any help would be appreciated, thanks.
How do I implement this without the startup class?
ASP.NET Core apps created with the web templates contain the application startup code in the Program.cs
file.
The Program.cs file is where:
Services required by the app are configured.
The app's request handling pipeline is defined as a series of middleware components.
You can refer to the code shown here, it implements this without the startup class:
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
...
// define your middleware pipeline
app.MapDefaultControllerRoute();
app.Run();
You can read App startup in ASP.NET Core to learn more.