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]) {
assert(!(T == dynamic && instanceName==null), 'You have to provide either a type or a name. Did you accidentally do `var sl=GetIt.instance();` instead of var sl=GetIt.instance;');
_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();
}