ApplicationBuilder (generic - includes worker services)
.NET Generic Host - .NET
Learn about the .NET Generic Host, which is responsible for app startup and lifetime management.

On how to implement a worker service look at
Template
- Calls a CreateApplicationBuilder method to create and configure a builder object.
using Example.WorkerService;
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<Worker>(); // registered via DI
IHost host = builder.Build();
host.Run();
Settings
When you build the following settings are made
- Sets the content root to the path returned by GetCurrentDirectory().
- Loads host configuration from:
- Environment variables prefixed withÂ
DOTNET_.
- Command-line arguments.
- Environment variables prefixed withÂ
- Loads app configuration from:
- appsettings.json.
- appsettings.{Environment}.json.
- Secret Manager when the app runs in theÂ
Development environment.
- Environment variables.
- Command-line arguments.
- Adds the following logging providers:
- Console
- Debug
- EventSource
- EventLog (only when running on Windows)
- Enables scope validation and dependency validation when the environment isÂ
Development.
Framework-Provided Services
The following services are registered on build
- IHostApplicationLifetime - interface to handle lifecycle events of service
- IHostLifetime - determines when the host starts and stops
- IHostEnvironment - get metadata on the environment such as isProduction or app name