singleton top-level constant

Singleton const singleton

An injectable class or module provider that provides a single instance.

A dependency annotated with singleton will only be instantiated once. The same instance will be used to satisfy all dependencies.

For example: @inject @singleton class Foo {}

@component
abstract class FooMaker {
  static final create = FooMaker$Component.create;

  // identical(getFoo(), getFoo()) is guaranteed to be true.
  Foo getFoo();
}

Implementation

const singleton = Singleton._();