get<T> method

T get <T>([String instanceName ])

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

Implementation

T get<T>([String instanceName]) {
  _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();
}