find<T> method

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

Find a dependency by type and optional tag (searches hierarchy).

Returns null if not found or if this scope is disposed.

Note: In v3.0.0, find<T>() will align with Zen.find<T>() by returning non-nullable T (throwing ZenDependencyNotFoundException when missing). Prefer findOrNull for nullable lookups and require for non-nullable lookups to stay forward-compatible.

Implementation

T? find<T>({String? tag}) {
  if (_disposed) {
    return null;
  }

  // First try in this scope
  final result = findInThisScope<T>(tag: tag);
  if (result != null) {
    return result;
  }

  // If not found and we have a parent, look there
  return parent?.find<T>(tag: tag);
}