addInjector method

  1. @override
void addInjector(
  1. covariant AutoInjectorImpl injector, {
  2. bool resolveUpward = false,
})
inherited

Inherit all instances and transforms from other AutoInjector object.

final injector = AutoInjector();
final otherInjector = AutoInjector();

injector.addInjector(otherInjector);

By default resolution is downward only: the added [injector] resolves the params of its binds against its own subtree, never against this ancestor. Set [resolveUpward] to `true` to let the added [injector] also resolve params against this ancestor (and its scope) as a fallback. Local/downward binds always take precedence — the ancestor is only consulted when the bind is not found in the added injector's own subtree.
The upward links must form a tree (a child points at its ancestor, never the reverse). Adding an edge that would create a mutual upward link throws an [UpwardResolutionCycle].

Implementation

@override
void addInjector(
  covariant AutoInjectorImpl injector, {
  bool resolveUpward = false,
}) {
  if (resolveUpward) {
    _assertNoUpwardCycle(injector);
    injector._upwardParent = this;
  }
  injectorsList.add(injector);
}