Learn About Pipeline in .NET 8.0

In .net core 8.0, we do not have startup.cs, and all things are merged into program.cs.

Program.cs in .NET 8.0

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllers();

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();

app.Run();

Key points

  1. Earlier we had a program.cs and startup.cs separately and program.cs take responsibility for loading application settings / Logging/IIS profiles, etc, which do not need to change every time but startup.cs contains settings related to the application DI container, Application pipeline, and middleware.
  2. In .Net8.0 we have only program.cs and are responsible for application bootstrap.
  3. We can Add Services using builder.Services.

Here, we can do DI

  1. Adding Configuration using builder.Configuration.
  2. Configure Logging using builder.Logging.
    Configure Logging
  3. We can use the below code for middleware.
    var app = builder.Build();
  4. Here, the app is an object of the Web Application class, which takes responsibility for middleware /pipeline.
    Web Application
  5. When we run this application, all settings get loaded into the builder object.
    Builder object

The below things get loaded when we run the application.

  1. Configuration
  2. Logging
  3. Env variables
  4. DI services
  5. Host related settings


Similar Articles