WebApplicationBuilder is the entry-point builder for an ASP.NET Core application. WebApplication.CreateBuilder(args) establishes core platform services, configuration, logging, and the Kestrel HTTP server, then returns a builder used to register application services. section 12.3.1
The usual lifecycle is deliberately split: configure services through builder.Services, call builder.Build() to produce a WebApplication, configure middleware and endpoints on that application, and call app.Run() to begin listening for requests. section 12.3.1
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run();
The minimal Program.cs pipeline shows the builder-to-application transition, endpoint mapping, and server startup in runnable order. section 12.3.1
Builder properties expose services needed during startup. builder.Configuration supplies application settings, while builder.Environment supplies IWebHostEnvironment information such as the selected environment. These values can determine which services are registered before Build is called. section 14.5.2 section 15.2.6
Environment-specific service registration
A Program.cs file can inspect builder.Environment and register TimeResponseFormatter with development-only dependencies, or HtmlResponseFormatter otherwise. After Build, middleware and endpoint handlers use the selected services through dependency injection. section 14.5.2
Configuration remains available after construction: builder.Configuration can configure services, and app.Configuration can configure the request pipeline. Endpoint parameters can also receive IConfiguration or IWebHostEnvironment through dependency injection. section 15.2.3 section 15.2.6

