injectFromAncestry<T> method

  1. @protected
  2. @nonVirtual
T injectFromAncestry<T>(
  1. Object token
)

Injects and returns an object representing token from ancestors.

Unlike inject, this only checks instances registered with any ancestry injector, not this injector. This is equivalent to the constructor parameters annotated with @SkipSelf.

Throws an error if token was not found.

Implementation

@protected
@nonVirtual
T injectFromAncestry<T>(Object token) {
  final result = injectFromAncestryOptional(token);
  if (identical(result, throwIfNotFound)) {
    throw errors.noProviderError(token);
  }
  return unsafeCast(result);
}