Program.cs is the entry point that configures dependency injection, middleware pipeline, and security. Middleware order matters — each component sees the request before passing it to the next. Full Program.cs Middleware Order Order Middleware Purpose 1 UseHttpsRedirection Redirect HTTP → HTTPS 2 UseCors Handle CORS preflight requests 3 UseRateLimiter Block excessive requests 4 UseAuthentication Validate JWT tokens 5 UseAuthorization Enforce [Authorize] attributes 6 Security headers X-Content-Type-Options, X-Frame-Options 7 MapControllers Route to controller actions Service Lifetimes Lifetime Used For Example Transient Lightweight, stateless Validators Scoped Per-request Repositories, Services, DbContext Singleton Shared across all requests NpgsqlDataSource, configuration