SmartInitializingSingleton class abstract interface

A singleton that wants a call once every non-lazy singleton has been created, at the end of startup.

Use it for work that needs the other beans to exist, such as registering every handler bean in a registry: during its own creation a bean cannot be sure the others are ready. It is mostly for framework code; an application can also listen for ContextRefreshedEvent.

// Register all handler beans once they exist.
@Service()
class HandlerRegistry implements SmartInitializingSingleton {
  HandlerRegistry(this.handlers);
  final ObjectProvider<Handler> handlers;

  @override
  void afterSingletonsInstantiated() => handlers.forEach(register);
}

Spring (Java):

@Service
class HandlerRegistry implements SmartInitializingSingleton {
  private final ObjectProvider<Handler> handlers;
  HandlerRegistry(ObjectProvider<Handler> handlers) {
    this.handlers = handlers;
  }
  @Override public void afterSingletonsInstantiated() {
    handlers.forEach(this::register);
  }
}

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

afterSingletonsInstantiated() → void
Called once at the end of preInstantiateSingletons, in the order the bean definitions were registered (not the creation order). Not called for a lazy singleton created later, nor for an object added with registerSingleton.
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