Boot class

Marks a method in a module to be executed during the boot phase.

Boot methods are called after all services are registered but before the application starts. They are useful for initialization tasks, warmup operations, or validation. Dependencies can be injected through method parameters.

Example:

@Module()
class DatabaseModule {
  @ProvideSingleton()
  Database createDatabase() => Database();

  @Boot()
  Future<void> runMigrations(Database db) async {
    await db.migrate();
  }

  @Boot()
  void validateConnection(Database db) {
    if (!db.isConnected) {
      throw Exception('Database connection failed');
    }
  }
}

The generated boot method will execute these in order:

@override
Future<void> boot(Injector i) async {
  await i<DatabaseModule>().runMigrations(i());
  i<DatabaseModule>().validateConnection(i());
}
Annotations
  • @Target.new({TargetKind.method, TargetKind.getter})

Constructors

Boot()
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited