liveBook · Manning

Convention-based approach

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

A convention-based approach determines application behavior from recognized names, method shapes, and structural conventions instead of explicit interfaces or registrations.

A convention-based approach lets framework behavior follow recognized names, method shapes, and application structure instead of requiring every relationship to be registered explicitly. In ASP.NET Core’s older Startup pattern, conventions organize configuration for services, middleware, and endpoints, but can be difficult for newcomers to discover. section 30.5

The convention gives applications a consistent shape, yet it can also hide how bootstrapping works. Configuration is commonly split between Program.cs and Startup, although services and middleware can be registered elsewhere through builder methods. section 30.5

Startup registration

A host builder can connect the web host to a Startup class with UseStartup<Startup>(). That single convention-based link allows Startup to define application services, middleware, and endpoints. section 30.5

public static IhostBuilder CreateHostBuilder(string[] args) =>
 Host.CreateDefaultBuilder(args)
   .ConfigureLogging(logging => logging.AddSeq())
   .ConfigureAppConfiguration(config => {})
   .ConfigureServices(s => {})
   .ConfigureHostConfiguration(config => {})
   .ConfigureWebHostDefaults(webBuilder =>
   {
       webBuilder.UseStartup<Startup>();
   });

Inspect the host-builder chain to see where Startup is selected and where related configuration conventions fit. section 30.5

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

How deep it goes
Explains the conventional structure and its tradeoffs, but stops short of detailing each Startup method or convention.
Examples
Uses a CreateHostBuilder chain ending in UseStartup<Startup>() to demonstrate conventional Startup registration.
What it assumes
Assumes basic familiarity with ASP.NET Core application files while highlighting the confusion caused by host-builder indirection and lambdas.
What you can do after
Evaluate conventional ASP.NET Core bootstrapping and locate where Startup is connected to host configuration.
How it connects
Connects Startup conventions with generic host, Program.cs, middleware, services, endpoints, and web-host configuration.

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.