findOrNullAsync<S> method
Asynchronously finds an instance of type S, returning null if not found.
tag: An optional tag to specify the instance.
Implementation
Future<S?> findOrNullAsync<S>({String? tag}) async {
final key = _getKey<S>(tag);
// 1. Try Local
final info = _registry[key];
if (info != null) {
return _findLocalAsync<S>(info as LevitDependency<S>, key, tag);
}
// 2. Try Cache
final cachedScope = _resolutionCache[key];
if (cachedScope != null) {
return cachedScope.findOrNullAsync<S>(tag: tag);
}
// 3. Try Parent
if (_parentScope != null) {
final instance = await _parentScope!.findOrNullAsync<S>(tag: tag);
if (instance != null) {
_cacheScope(key, _parentScope!);
return instance;
}
}
return null;
}