How To Add Startup - Cs Class in ASP - NET Core 6 Project
How To Add Startup - Cs Class in ASP - NET Core 6 Project
NET
Core 6 Project
Munesh Sharma
Updated date Jun 02, 2022
9.1k
1
2
facebook
o
o
o
o
Expand
Here we are going to learn how to add the startup.cs file in the Asp.net core application when we
are working with the ASP.NET 6.0 project, so let's start.
If you are creating your asp.net core application with 6.0 then you will not see
the Startup.cs class in project files, as we used to see in the previous version of the asp.net core
application, and we used to register the dependencies of the application and the middleware.
But if you still want to write your middleware and dependencies in startup class, here we will
learn how to add the startup.cs class in ASP.NET 6.0 project.
So in the above code, you can see, that we have added a startup class and added 2
methods ConfigureServices and Configure as we used to have in the previous version of asp.net.
After adding the above file now remove Dependencies and services code from
the program.cs class and put that code into ConfigureServices() method and same middleware
code in Configure method and remove from the program.cs class.
After updating our Program.cs and Startup.cs class, we have to call startup.cs class from
program.cs class like below
Now if you run your application, it should run without any error.
Previously it was not possible to change the startup.cs methods name, but now we can write
method name as we want and write the respective code in these methods and can call same
from the program.cs class.