# findAutowireCandidates method

1. @protected

Future<Map<String, Object>> findAutowireCandidates(

1. String? podName,
2. DependencyDescriptor descriptor

)

Finds all autowire candidates for a dependency.

This method searches for all pods that match the dependency type and are valid autowire candidates according to the dependency descriptor.

`podName` the name of the pod requiring the dependency `descriptor` the dependency descriptor

Returns a Map of candidate pod names to instances

## Implementation

    @protected
    Future<Map<String, Object>> findAutowireCandidates(String? podName, DependencyDescriptor descriptor) async {
      final candidates = <String, Object>{};
      final type = descriptor.type;

      final podsOfType = await PodUtils.podsOfTypeIncludingAncestors(this, type, includeNonSingletons: true, allowEagerInit: true);

      for (final entry in podsOfType.entries) {
        final candidate = entry.key;
        final pod = entry.value;
        // Check if pod is an autowire candidate
        if (isAutowireCandidate(candidate, descriptor) && !selfReferenced(podName, candidate)) {
          if (containsSingleton(candidate)) {
            // Early reference handling
            final earlyRef = await getSingletonCache(candidate);
            final value = earlyRef?.getValue();

            if (value != null) {
              candidates[candidate] = value;
            } else {
              // Might throw exception instead of this...
              candidates[candidate] = pod;
            }
          } else {
            candidates[candidate] = pod;
          }
        }
      }

      return candidates;
    }