injectFromSelf<T> method

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

Injects and returns an object representing token from this injector.

Unlike inject, this only checks this itself, not the parent or the ancestry of injectors. This is equivalent to constructor parameters annotated with @Self.

Throws an error if token was not found.

Implementation

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