liveBook · Manning

WebApplicationBuilder

As explained in Pro ASP.NET Core 7, Tenth Edition

WebApplicationBuilder is the ASP.NET Core builder type that configures an application and its services before constructing the web application.

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

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Explains platform setup, service registration, Build transition, configuration access, and environment selection without descending into framework internals.
Examples
Uses a minimal Hello World endpoint, conditional formatter services, configuration-driven setup, middleware, and environment-aware endpoints.
What it assumes
Assumes basic C# and ASP.NET Core terminology while demonstrating service registration, configuration access, middleware, endpoints, and application startup.
What you can do after
Build from scratch a configured ASP.NET Core application with registered services, environment-specific choices, middleware, and mapped endpoints.
How it connects
Connects dependency injection, application configuration, environments, middleware, endpoint routing, and the Kestrel HTTP server.

Also explained in

Compare how 2 books explain WebApplicationBuilder →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.