Startup.cs in ASP.NET Core

Startup.cs file in core application contain all configuration and hosting related information.

Startup class or Startup.cs file is generated as part of the default Core template. Startup class is the entry point of application. It configures the request pipeline that handles all requests made to the application.

Startup.cs is used for configuration & Startup Class is mandatory in Core application
What is Startup class in Core?

Can we rename the startup class to some other name?
Yes, Finally this Startup.cs is used in Program class for hosting the application, So renaming this class will not make any difference.

Startup Class Constructor Dependency Injection

Here you can see how new instance of "IConfiguration" is being created, by setting up IConfiguration instance in startup constructor will allow us to access all configuration related information.

public class Startup
    public IConfiguration Configuration { get; }
    public Startup(IConfiguration configuration)
        Configuration = configuration;

In Startup file you can see an example of dependency injection

startup.cs in core
ConfigureServices Method in Startup.cs

In ConfigureService method we can configure any service in that application, to do that all service to be added in IServiceCollection
For example you can see how below methods are added
services.AddMvc(); this was added by default

public class Startup
{ // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)

In above example we are try to configure a DbConnectionConfig class we read information from appSetting.json class, so we want when service starts, all configuration information to be available in custom configuration class

Configure Method in Startup.cs
This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
if (env.IsDevelopment())
DbConnectionString = string.Format("Server={0};Database={1};
User ID={2};Password={3};Trusted_Connection=False;
app.UseMvc(routes =>
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");
Asp.Net Core C# Examples | Join Asp.Net MVC Course