Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to merge Startup.cs into Program.cs

I’m new to ASP.NET Core. I’m using ASP.NET Core 7. I read that in ASP.NET Core 7 they got rid of Startup.cs. Can someone show me how to merge Startup.cs into Program.cs in this example.

https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/2-WebApp-graph-user/2-1-Call-MSGraph

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I read that in ASP.NET Core 7 they got rid of Startup.cs.

Not exactly. ASP.NET Core 6 introduced a new so called minimal hosting model (which is used by the default template). But you are free to keep the generic hosting model if you want.

How to merge Startup.cs into Program.cs

In short – move everything from ConfigureServices to before var app = builder.Build(); call and everything from Configure – after it (check out code generated by the default template). To setup services you can use builder.Services, cofiguration is accessible from both builder and app via correspondingly named property and use app to perform the calls from Startup.Configure.

See also:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading