Skip to content

Treat the only one default candidate as effectively primary #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Pankraz76
Copy link
Owner

@Pankraz76
Copy link
Owner Author

nice approach looks perfectly fine to me.

Copy link
Owner Author

@Pankraz76 Pankraz76 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well done

}
}
}
return candidateBeanName;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe filtering would highlight the main condition:

.filter(entry -> entry.getValue().isAutowireCandidate() && entry.getValue().isDefaultCandidate())

protected String determineEffectivelyPrimaryCandidate(Map<String, Object> candidates, Class<?> requiredType) {
    return candidates.entrySet().stream()
        .map(entry -> Map.entry(entry.getKey(), transformedBeanName(entry.getKey())))
        .filter(entry -> containsBeanDefinition(entry.getValue()))
        .map(entry -> Map.entry(entry.getKey(), getMergedLocalBeanDefinition(entry.getValue())))
        .filter(entry -> entry.getValue().isAutowireCandidate() && entry.getValue().isDefaultCandidate())
        .map(Map.Entry::getKey)
        .reduce((a, b) -> null) // Ensures only one candidate; otherwise, null
        .orElse(null);
}

Its although nice, if a method has only has one return statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve BeanFactory/ObjectProvider to select the only one default candidate among non-default candidates
2 participants