Skip to main content

Explain the Application Lifetime events in ASP.NET Core (IHostApplicationLifetime).

Junior .NET Core
Quick Answer IHostApplicationLifetime provides three events: ApplicationStarted (app is fully started), ApplicationStopping (shutdown triggered, still running), ApplicationStopped (shutdown complete). Use these to run startup logic (warm caches) or cleanup (flush logs, close connections). Inject IHostApplicationLifetime wherever you need lifecycle hooks.

Answer

IHostApplicationLifetime (renamed to IHostApplicationLifetime / IHostApplicationLifetime in newer versions) exposes three key notifications:

  • ApplicationStarted – Fired when the app is fully started and ready to serve requests.
  • ApplicationStopping – Fired when the app begins a graceful shutdown (e.g., SIGTERM in containers).
  • ApplicationStopped – Fired when shutdown is complete and cleanup has finished.

These events are used to warm up caches, start or stop background tasks, flush logs, and release resources in cloud and container environments.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice