program-and-pipeline

Primary docs: - https://learn.microsoft.com/aspnet/core/fundamentals/ - https://learn.microsoft.com/aspnet/core/fundamentals/minimal-apis/webapplication - https://learn.microsoft.com/aspnet/core/fundamentals/middleware/ - https://learn.micr

Program And Pipeline

Primary docs:

Startup Shape

Prefer the modern hosting model:

  1. Create var builder = WebApplication.CreateBuilder(args);
  2. Register services on builder.Services
  3. Build var app = builder.Build();
  4. Configure middleware in the correct order
  5. Map endpoints
  6. Call app.Run();

Use older Startup patterns only when the repository already uses them or the task is migration.

Service Registration

Configuration Defaults

WebApplication.CreateBuilder already loads configuration from common providers such as:

For secrets:

Middleware Order

Middleware order is a frequent source of broken behavior. Favor this shape and adjust only with a concrete reason:

  1. Forwarded headers if behind a proxy or load balancer
  2. Exception handling and HSTS for non-development environments
  3. HTTPS redirection
  4. Static files
  5. Routing when explicit routing middleware is needed
  6. CORS when endpoints require it
  7. Authentication
  8. Authorization
  9. Endpoint-specific middleware such as rate limiting or session as required
  10. Endpoint mapping with MapRazorPages, MapControllers, MapGet, MapHub, or MapGrpcService

Important ordering rules:

Routing And Endpoints

Error Handling

Logging And Diagnostics

Static Assets And Web Root

Architectural Defaults