find<S> method
Finds the registered type <S
> (or tag
)
In case of using Get.create
to register a type <S
> or tag
,
it will create an instance each time you call find.
If the registered type <S
> (or tag
) is a Controller,
it will initialize it's lifecycle.
Implementation
S find<S>({String? tag}) {
final String key = _getKey(S, tag);
if (isRegistered<S>(tag: tag)) {
final _InstanceBuilderFactory<T> dep =
_singl[key]! as _InstanceBuilderFactory<T>;
/// although dirty solution, the lifecycle starts inside
/// `initDependencies`, so we have to return the instance from there
/// to make it compatible with `Get.create()`.
final S? i = _initDependencies<S>(name: tag);
return i ?? dep.getDependency() as S;
} else {
throw Exception(
'"$S" not found. You need to call "Get.put($S())" or "Get.lazyPut(()=>$S())"',
);
}
}