.NET › Generic Host
What is the Generic Host in .NET, and what problem does it standardize across different application types?
BeginnerAnswer
The Generic Host (IHost, built via Host.CreateApplicationBuilder or WebApplication.CreateBuilder) provides a unified application startup model handling dependency injection container setup, configuration loading, logging configuration, and graceful start/stop lifecycle management -- standardizing this infrastructure across ASP.NET Core web apps, Worker Services, and console applications, so the same DI, configuration, and logging patterns work consistently regardless of the application type.
// Worker Service using Generic Host
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<Worker>();
var host = builder.Build();
host.Run();
// ASP.NET Core app using the same underlying Generic Host infrastructure
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.Run();Real-world example A team building both a web API and a separate background worker service uses the same familiar DI registration and configuration patterns in both projects, since both are built on the shared Generic Host foundation despite one having a web server and the other not.