spotAsync<T> method
Resolve and return an async singleton of type T.
Resolution order is the same as spot.
Type Parameters:
T: The type to resolve (must be registered in this scope or parent)
Parameters:
name: Optional name qualifier for named instances
Returns: Future<T> that resolves to the instance
Throws:
- SpotException if
Tis not registered in this scope or any parent - SpotException if circular dependency detected
Implementation
Future<T> spotAsync<T>({String? name}) async {
final key = SpotKey<T>(T, name);
// Fast path: check singleton cache first
if (_singletonCache.containsKey(key)) {
if (logging) log.v('Cache hit in scope for async $key');
return _singletonCache[key] as T;
}
// Check local registry
if (registry.containsKey(key)) {
return await _resolveLocalAsync<T>(key);
}
// Fall back to parent
if (parent != null) {
if (logging) log.v('Falling back to parent for async $key');
return await parent!.spotAsync<T>(name: name);
}
// Not found in this scope or any parent
final registeredTypes = _getAllRegisteredKeys().map((k) => k.toString()).join(', ');
throw SpotException(
'Type $key is not registered in this scope or any parent scope.\n'
'Registered in this scope: ${registry.keys.map((k) => k.toString()).join(', ')}\n'
'All registered types: ${registeredTypes.isNotEmpty ? registeredTypes : '(none)'}'
);
}