Utilize ASP.NET Core Application Lifetime Events

At times you need to know when your ASP.NET Core web application is being started and shutdown. One of the lesser known features of ASP.NET Core is the IApplicationLifetime interface that allows you to wire some logic when such application lifetime events occur. This article briefly discusses the IApplicationLifetime interface and its functionality.

http://www.binaryintellect.net/articles/535d4ca7-9726-46cf-bc64-64e94ec55f6e.aspx