get<T> method

T get <T>([String instanceName ])

retrieves or creates an instance of a registered type T depending on the registration function used for this type or based on a name.

Implementation

T get<T>([String instanceName]) {
  assert(!(!(const Object() is! T) && instanceName == null),
      'GetIt: You have to provide either a type or a name. Did you accidentally do  `var sl=GetIt.instance();` instead of var sl=GetIt.instance;');
  assert(!(((const Object() is! T) && instanceName != null)),
      'GetIt: You have to provide either a type OR a name not both.');

  _ServiceFactory<T> object;
  if (instanceName == null) {
    object = _factories[T];
  } else {
    object = _factoriesByName[instanceName];
  }
  if (object == null) {
    if (instanceName == null) {
      throw Exception(
          "Object of type ${T.toString()} is not registered inside GetIt");
    } else {
      throw Exception(
          "Object with name $instanceName is not registered inside GetIt");
    }
  }
  return object.getObject();
}