Generic Host is an awesome way to host all sort of long running tasks and applications, e.g. messaging, background tasks, etc.
-
Configure logging for your Generic Host. This technique will be used in the subsequent samples.
-
This is the hello world equivalent of a Generic Host service.
-
Hello World using Console Lifetime
Use
UseConsoleLifetime
implicitly. -
Demonstrates the startup and shutdown order of hosted services.
-
Demonstrates starting and stopping the host programmatically.
-
A service with timed execution
Demonstrate processing a task on a regular interval using
Task.Delay
. -
Configure Host using Dictionary
Demonstrate the way to inject configuration values to the host using Dictionary.
-
Set your environment using
EnvironmentName.Development
orEnvironmentName.Production
orEnvironmentName.Staging
. -
Listen to IHostApplicationLifetime events
Inject
IHostApplicationLifetime
and listen toApplicationStarted
,ApplicationStopping
andApplicationStopped
events. This is important to allow services to be shutdown gracefully. The shutdown process blocks untilApplicatinStopping
andApplicationStopped
events complete.
dotnet8