Skip to content

You're viewing documentation for a pre-release version. View the latest stable version

Protocol

LifecycleHandler

Provides a way to hook into lifecycle events of a Vapor application. You can register your handlers with the Application to be notified when the application is about to start up, has started up and is about to shutdown
protocol LifecycleHandler : Sendable

Overview

For example

 struct LifecycleLogger: LifecycleHander {
   func willBoot(_ application: Application) async throws {
       application.logger.info("Application about to boot up")
   }

   func didBoot(_ application: Application) async throws {
       application.logger.info("Application has booted up")
   }

   func shutdown(_ application: Application) async {
       application.logger.info("Will shutdown")
   }
 }

You can then register your handler with the application:

application.lifecycle.use(LifecycleLogger())

Topics

Instance Methods

Relationships

Inherits From

  • Swift.Sendable
  • Swift.SendableMetatype