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.

Example:

@provide
@singleton
class Foo {}

@injector
abstract class FooMaker {
  static final create = FooMaker$Injector.create;

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

Implementation

const singleton = const Singleton._();