Skip to main content
The bootstrap.rs file is your application’s central configuration point for registering services, global middleware, and performing runtime initialization. It’s called during application startup, before the server begins handling requests.

Overview

Every Kit application has a src/bootstrap.rs file that contains a register() function:

When Bootstrap Runs

The bootstrap file is called in main.rs during the application startup sequence:
This sequence ensures that environment variables and configuration are available before services are initialized.

What to Register in Bootstrap

Database Initialization

Initialize the database connection to make it available throughout your application:

Global Middleware

Register middleware that should run on every request:
Global middleware runs on every request in the order registered. For route-specific middleware, see the Middleware documentation.

Services with Runtime Configuration

Register services that need environment variables, config files, or other runtime values:

Trait Bindings

Bind interfaces to concrete implementations for dependency injection:

Bootstrap vs #[injectable]

Kit provides two ways to register services:

Use #[injectable] for:

Use Bootstrap for:

Complete Bootstrap Example

Here’s a comprehensive example showing common patterns:

Summary