What is the generic host, and how does it differ from the web host?
Quick Answer
The generic host (IHost) provides DI, configuration, logging and a lifetime for any .NET app — including non-web Worker Services. The web host is the generic host plus Kestrel and the HTTP pipeline. Since .NET 3.0 the web host is built on the generic host; WebApplication is a streamlined wrapper over both.
The generic host is the general-purpose .NET application host — it gives you dependency injection, configuration, logging, and a managed lifetime, and it works for any app, including a Worker Service that has no web server at all. The web host is the generic host with Kestrel and the HTTP middleware pipeline layered on. Since .NET 3 the web host is actually built on top of the generic host, and WebApplication.CreateBuilder is a convenience wrapper over the whole thing. So a background queue processor just uses the generic host and skips all the HTTP stuff.
- Generic host:
Host.CreateApplicationBuilder(args)→ services, config, logging, hosted services, graceful start/stop. - Web host adds:
ConfigureWebHostDefaults/WebApplication.CreateBuilder→ Kestrel, IIS integration,IWebHostEnvironment, the middleware pipeline. - A Worker Service (background processor, queue consumer) uses just the generic host — no Kestrel, no HTTP.
- Both give you
IHostApplicationLifetimefor shutdown hooks and honourSIGTERMfor graceful container shutdown.