get<T extends Object> method

T get<T extends Object>([
  1. Object? token
])

Retrieves a dependency of type T.

  • token: An optional token (e.g., InjectorToken) or Type to disambiguate between different implementations of the same type.

Throws an InjectorError if the dependency was not requested or cannot be found.

Implementation

T get<T extends Object>([Object? token]) {
  var service = getOptional<T>(token);
  if (service != null) return service;
  throw InjectorError("Requested Type or InjectorToken is null: ${_getTokenRepresentation(token)}");
}