liveBook · Manning

Chapter 30: Building ASP.NET Core apps with the generic host and Startup

What you will learn in chapter 30 of ASP.NET Core in Action, 3e

This chapter introduces the older generic-host-and-Startup approach to bootstrapping ASP.NET Core apps, compares it with minimal hosting, and explains when each approach fits.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduces the older generic-host-and-Startup approach to bootstrapping ASP.NET Core apps, compares it with minimal hosting, and explains when each approach fits.

Key terms: generic host, IHost, IHostBuilder, Startup class, minimal hosting, WebApplication, Program.cs, Startup.cs, bootstrapping, WebApplicationBuilder

30.1 Separating concerns between two files

This section introduces the pre-.NET-6 generic-host application structure, which separates ASP.NET Core bootstrapping between Program.cs and Startup.cs.

Key terms: generic host, Program.cs, Startup.cs, static void Main(), top-level statements, Startup, host object, Kestrel, Internet Information Services (IIS), configuration sources

30.2 The Program class: Building a Web Host

This section explains how a Startup-based ASP.NET Core application's Program class configures, builds, and runs an IHost web host.

Key terms: Main, IHostBuilder, Build(), IHost, Run(), Program, Startup, UseStartup<>, services, middleware pipeline

30.3 The Startup class: Configuring your application

This section explains how a Startup class separates service registration from middleware and endpoint configuration when building an ASP.NET Core app with an IHostBuilder.

Key terms: Startup, ConfigureServices, Configure, IHostBuilder, DI container, reflection, IStartup, StartupBase, IConfiguration, IApplicationBuilder

30.4 Creating a custom IHostBuilder

This section explains what Host.CreateDefaultBuilder configures, why starting from its defaults is usually preferable to a new HostBuilder, and how later configuration calls customize those defaults.

Key terms: Host.CreateDefaultBuilder, IHostBuilder, UseContentRoot, ConfigureHostingConfiguration, ConfigureAppConfiguration, ConfigureLogging, ContentRoot, WebRoot, DOTNET_ENVIRONMENT, IWebHostEnvironment

30.5 Understanding the complexity of the generic host

This section explains why the generic host and Startup bootstrapping pattern can be difficult to understand and how minimal hosting reduces much of that complexity.

Key terms: Program.cs, Startup, ConfigureServices(), Configure(), HostBuilder.ConfigureServices(), WebHostBuilder.Configure(), IHostBuilder, IWebHostBuilder, ConfigureWebHostDefaults(), ConfigureHostConfiguration()

30.6 Choosing between the generic host and minimal hosting

This section explains when to retain the generic host rather than adopt minimal hosting, and emphasizes that both hosting models use the same core ASP.NET Core concepts.

Key terms: minimal hosting, WebApplication, WebApplicationBuilder, generic host, IHost, Startup, .NET 7, configuration, middleware, dependency injection

30.7 Summary

This summary contrasts the pre-.NET 6 generic host and Startup application model with minimal hosting, explaining their setup, configuration responsibilities, and when to choose each.

Where this is used later

Concepts explained in this chapter

← Chapter 29: Improving your application’s security Chapter 31: Advanced configuration of ASP.NET Core →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.