ASP.NET Core exposes events for the whole application life cycle. You can hook up to these events to be notified of when they are about to happen. These events are called by the host with the use of the application (IHostLifetime), which was explained in Chapter 1, Getting Started with ASP.NET Core. The entry point to this is the IHostApplicationLifetime interface, which you can get from the dependency injection framework. It exposes the following properties:
- ApplicationStarted (CancellationToken): Raised when the host is fully started and is ready to wait for requests.
- ApplicationStopping(CancellationToken): Raised when the application is about to stop in what is known as a graceful shutdown. Some requests may still be in process.
- ApplicationStopped(CancellationToken): Raised when the application is fully stopped.
Each of these is a CancellationToken property, which means that it can be passed...