Skip to content
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

EachBean: Allow to inject the origin bean and the registration #10902

Merged
merged 3 commits into from
Jun 20, 2024

Conversation

dstepanov
Copy link
Contributor

For each bean functionality, we require a qualifier to properly identify the origin bean, but there are use cases where the bean cannot be modified.

Previously, we would allow each bean without a qualifier, but that will fail when you want to inject an origin; this PR is allowing to inject it.

Another solution for the qualifiers would be to add a qualifier that matches the bean type by the exact class, and maybe it can be reused elsewhere.

This should target 4.6 after it's created

@dstepanov dstepanov requested a review from graemerocher June 13, 2024 11:48
* @return The qualifier
* @since 4.6
*/
public static <T> Qualifier<T> eachBeanOf(BeanDefinition<?> beanDefinition) {
Copy link
Contributor

Choose a reason for hiding this comment

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

don't think we should make this public API since it quite internal specific. Either way I would name it childOf or descendedFrom something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made private


@Override
public String toString() {
return "EachBeanQualifier('" + beanDefinition + "')";
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens with a qualifier like this when I inject Map<String, Foo>? Please add tests for maps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this moment, it fails because there is no name. I think in this case we should throw an error saying that Map cannot be used on multiple beans that don't have the name defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the message a bit reflecting that it doesn't need to be each bean + tests

@graemerocher
Copy link
Contributor

I created the 4.6.x branch please target that. Also could you describe what issue this is trying to solve?

@dstepanov
Copy link
Contributor Author

I want to add:

@EachBean(jakarta.ws.rs.ext.MessageBodyWriter.class)
public final class JaxRsMessageBodyWriter<T> implements MessageBodyWriter<T> {

    private final jakarta.ws.rs.ext.MessageBodyWriter<T> messageBodyWriter;

    JaxRsMessageBodyWriter(jakarta.ws.rs.ext.MessageBodyWriter<T> messageBodyWriter) {
        this.messageBodyWriter = messageBodyWriter;
    }

But Jax-Rs "beans" don't have any qualifier that fails when the origin bean is injected into the constructor.

@dstepanov dstepanov changed the base branch from 4.5.x to 4.6.x June 13, 2024 16:12
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 New Bugs (required ≤ 0)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@graemerocher graemerocher merged commit c04c2c0 into 4.6.x Jun 20, 2024
16 of 17 checks passed
@graemerocher graemerocher deleted the eachbean branch June 20, 2024 08:15
@graemerocher graemerocher added the type: improvement A minor improvement to an existing feature label Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: improvement A minor improvement to an existing feature
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants