isAutoStartup abstract method

bool isAutoStartup()

An extension of the Lifecycle interface for those objects that require to be started upon ApplicationContext refresh and/or shutdown in a particular order.

The isAutoStartup return value indicates whether this object should be started at the time of a context refresh. The callback-accepting stop method is useful for objects that have an asynchronous shutdown process.

This interface extends Phased, and the getPhase method's return value indicates the phase within which this Lifecycle component should be started and stopped. The startup process begins with the lowest phase value and ends with the highest phase value. The shutdown process applies the reverse order.

Phase-based Startup/Shutdown

  1. Startup: Phase -1000 → -100 → 0 → 100 → 1000
  2. Shutdown: Phase 1000 → 100 → 0 → -100 → -1000

Usage Example

class MessageBroker implements SmartLifecycle {
  bool _running = false;

  @override
  bool isAutoStartup() => true;

  @override
  int getPhase() => 0;

  @override
  void start() {
    if (!_running) {
      connectToBroker();
      _running = true;
    }
  }

  @override
  void stop(Runnable? callback) {
    if (_running) {
      disconnectFromBroker(() {
        _running = false;
        callback?.run();
      });
    } else {
      callback?.run();
    }
  }

  @override
  bool isRunning() => _running;
}

Returns true if this Lifecycle component should get started automatically by the container at the time of ApplicationContext refresh.

A value of false indicates that the component is intended to be started through an explicit start() call instead, analogous to a plain Lifecycle implementation.

Return Value

Returns true if this component should be started automatically, false otherwise.

Implementation

bool isAutoStartup();