liveBook · Manning

Minimal hosting

As explained in ASP.NET Core in Action, 3e

Minimal hosting is an ASP.NET Core application-hosting style that consolidates bootstrapping in an imperative application entry point with reduced convention and builder ceremony.

Minimal hosting is the default way to bootstrap an ASP.NET Core web app. WebApplicationBuilder and WebApplication keep setup in one imperative entry point, rather than splitting it between a generic host builder and a Startup class. They were introduced in .NET 6 to make getting started simpler. section 30.0 section 30.5

The two types make common setup tasks easier to find:

  • Use WebApplicationBuilder.Services to register dependency-injection services. Configuration and environment are available as builder properties. section 30.5 section 30.7
  • Use WebApplication to add middleware and map endpoints. It automatically adds some middleware, including routing and endpoint middleware; middleware you add still runs in the order you add it. section 30.5 section 30.7

Choosing a starting point

For a new HTTP app, start with the WebApplication-based template and keep service registration and pipeline setup together. For a queue-processing worker that handles no HTTP requests, the worker template instead builds an IHost with Host.CreateDefaultBuilder(args). An existing app using the generic host and Startup can keep that supported approach when upgrading to .NET 7. section 30.6 section 34.2.1

Minimal hosting simplifies the surface, but does not replace the generic host underneath. Choose the generic host when you need fine control over building IHost; for most new ASP.NET Core web apps, minimal hosting is the easier starting point. section 30.5 section 30.6

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains builder properties and middleware behavior, while leaving the underlying generic-host abstraction largely hidden.
Examples
Contrasts an ASP.NET Core web app with a worker template that calls Host.CreateDefaultBuilder(args).
What it assumes
Introduces the simpler bootstrap path for newcomers without requiring knowledge of generic-host internals.
What you can do after
Apply it via WebApplicationBuilder and WebApplication to bootstrap a typical web app and recognize when the generic host fits better.
How it connects
Connects WebApplicationBuilder and WebApplication to dependency injection, middleware, endpoint routing, and the generic host.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.