single<T> method

void single<T>(
  1. ScopeKey<T> key,
  2. T factory()
)

Injects a single value into the Scope.

A single may use values, other singles and sequences registered within the same Scope.

Each single is eagerly called when Scope.run is called and are fully resolved when the Scope.run's s action is called.

Implementation

void single<T>(ScopeKey<T> key, T Function() factory) {
  if (_singles.containsKey(key)) {
    throw DuplicateDependencyException(key);
  }
  _singles.putIfAbsent(key, () => factory);
}