get<T> method
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]) {
throwIfNot(
!(!(const Object() is! T) && instanceName == null),
ArgumentError(
'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;'),
);
throwIfNot(
!(((const Object() is! T) && instanceName != null)),
ArgumentError(
'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) {
throwIf(
instanceName == null,
ArgumentError.value(
T, "Object of type ${T.toString()} is not registered inside GetIt"),
);
throwIf(
instanceName != null,
ArgumentError.value(instanceName,
"Object with name $instanceName is not registered inside GetIt"),
);
}
return object.getObject();
}