micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6k stars 1.04k forks source link

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

Closed dstepanov closed 1 week ago

dstepanov commented 2 weeks ago

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

graemerocher commented 2 weeks ago

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

dstepanov commented 2 weeks ago

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.

sonarcloud[bot] commented 2 weeks ago

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