Skip to content

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 willBootAsync(_ application: Application) async throws {
       application.logger.info("Application about to boot up")
   }

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

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

You can then register your handler with the application:

application.lifecycle.use(LifecycleLogger())

Topics

Instance Methods

  • didBoot(_:)
    Called when the application has booted up
  • didBootAsync(_:)
    Called when the application is about to boot up. This is the asynchronous version of didBoot(_:). When adopting the async APIs you should ensure you provide a compatitble implementation for didBoot(_:) as well if you want to support older users still running in a non-async context Note your application must be running in an asynchronous context and initialised with make(_:_:) for this handler to be called
  • shutdown(_:)
    Called when the application is about to shutdown
  • shutdownAsync(_:)
    Called when the application is about to boot up. This is the asynchronous version of shutdown(_:). When adopting the async APIs you should ensure you provide a compatitble implementation for shutdown(_:) as well if you want to support older users still running in a non-async context Note your application must be running in an asynchronous context and initialised with make(_:_:) for this handler to be called
  • willBoot(_:)
    Called when the application is about to boot up
  • willBootAsync(_:)
    Called when the application is about to boot up. This is the asynchronous version of willBoot(_:). When adopting the async APIs you should ensure you provide a compatitble implementation for willBoot(_:) as well if you want to support older users still running in a non-async context Note your application must be running in an asynchronous context and initialised with make(_:_:) for this handler to be called

Relationships

Inherits From

  • Swift.Sendable
  • Swift.SendableMetatype