When building an ASP.NET Core Web API, Program.cs can quickly become the central place where everything comes together.

Database configuration, dependency injection, authentication, authorization, CQRS, validation, exception handling, CORS, Swagger, and application middleware all need to be configured correctly.

In this article, I'll walk through how I configured these pieces in an ASP.NET Core Web API using Entity Framework Core, ASP.NET Identity, JWT authentication, MediatR, FluentValidation, and Clean Architecture concepts.

1. Creating the WebApplication Builder

The first step is creating the application builder: