Pro EP 45 : Program.cs File Explained in .NET 6

Muhammad Waseem
Become .NET Pro !
2 min readApr 23, 2023

Since .NET 6 this file is the entry point of our application. It is doing work of both Program and Startup file if we look it via previous versions eye. This file has three things to do.

- Build Application
- Configure services required by app
- App request handling pipelines (Middlewares)

🎯 Configuring the services was performed in ConfigureServices method in older versions and middleware’s were added in Configure method but now we don’t us those methods.

♉ Services
We need to tell our application about the services we are going to use in our application and we inject their dependencies in this part. These are the common services.

  • Adding CORS
  • Add HTTP Context
  • Adding Database Context
  • Add Controllers and Swagger
  • Application Dependency Injections

♉ Middleware
It is software that’s assembled into an app pipeline to handle requests and responses. Each component chooses whether to pass the request to the next component in the pipeline. We define order of these pipelines in this part. Following are the common middleware.

  • Routing
  • Exception handling
  • Authentication and authorization
  • CORS (Cross-Origin Resource Sharing)
  • Response compression
  • Request validation
  • Response caching

Whenever you’re ready , there are 3 ways I can help you

  1. Subscribe my Weekly .NET Newsletter of C#/.NET with 1950+ Software Engineers.
  2. Promote yourself to 1950+ subscribers by sponsoring my newsletter (Reach me at mwaseemzakir@gmail.com)
  3. Download my eBook at Gum road that contains 30+ .NET Tips (With 950+ Downloads)

--

--