find<S> method

S find<S>({
  1. String? tag,
})

Finds the registered type <S> (or tag) In case of using June.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 key = _getKey(S, tag);
  if (isRegistered<S>(tag: tag)) {
    final dep = _singl[key];
    if (dep == null) {
      if (tag == null) {
        throw 'Class "$S" is not registered';
      } else {
        throw 'Class "$S" with tag "$tag" is not registered';
      }
    }

    /// although dirty solution, the lifecycle starts inside
    /// `initDependencies`, so we have to return the instance from there
    /// to make it compatible with `June.create()`.
    final i = _initDependencies<S>(name: tag);
    return i ?? dep.getDependency() as S;
  } else {
    // ignore: lines_longer_than_80_chars
    throw '"$S" not found. You need to call "June.put($S())" or "June.lazyPut(()=>$S())"';
  }
}