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

 

This chapter covers

  • Using the generic host and a Startup class to bootstrap your ASP.NET Core app
  • Understanding how the generic host differs from WebApplication
  • Building a custom generic IHostBuilder
  • Choosing between the generic host and minimal hosting

Some of the biggest changes introduced in ASP.NET Core in .NET 6 were the minimal hosting APIs, namely the WebApplication and WebApplicationBuilder types you’ve seen throughout this book. These were introduced to dramatically reduce the amount of code needed to get started with ASP.NET Core and are now the default way to build ASP.NET Core apps.

Before .NET 6, ASP.NET Core used a different approach to bootstrap your app: the generic host, IHost, IHostBuilder, and a Startup class. Even though this approach is not the default in .NET 7, it’s still valid, so it’s important that you’re aware of it, even if you don’t need to use it yourself. In this chapter I introduce the generic host and show how it relates to the minimal hosting APIs you’re already familiar with. In chapter 34 you’ll learn how to use the generic host approach to build nonweb apps too.

30.1 Separating concerns between two files

30.2 The Program class: Building a Web Host

30.3 The Startup class: Configuring your application

30.4 Creating a custom IHostBuilder

30.5 Understanding the complexity of the generic host

30.6 Choosing between the generic host and minimal hosting

Summary

sitemap