[Solved] Where is startup.cs class in Blazor

Admin | Last updated 09/04/2024

With .Net 6, Microsoft unified Program.cs and Startup.cs class files

So now in .Net 6+, we can have the Startup.cs file's code in Program.cs only

There were two main use cases of Startup.cs

  1. Configuring the Services (Registering Dependencies etc) - in ConfigureServices method
  2. Configuring the Http Request Pipeline (with Middewares etc) - Configure method

Where to add these in Program.cs

You will see a line in Program.cs in .Net 6+

var app = builder.Build();

Technically, this line is the separator of ConfigureServices and Configure method

  • So whatever you had in ConfigureServices method till .Net 5, you will need to add that before this line ( Use builder.Services to register the service dependencies, and builder.Configuration to access configuration from appsettings or environment variables)
  • and whatever you had in Configure method till .Net 5, you will need to add that after this line (Use app.Services to access the IServiceProder to resolve any dependency and app.Configuration to access configuration from appsettings or environment variables)

Comments

No comments yet. Be the first to leave a comment

Add a New Comment
An unhandled error has occurred. Reload 🗙