whats the easiest way to obtain the InjectionPoint when your producer method is producing a scoped bean? For some reason the spec does only allow injection of the InjectionPoint when you are producing scoped beans. Is there an easy way to do that or some kind of bolg entry or tutorial for that?
For clarifiaction, here is what Id like to do, but what is forbidden by the spec:
@Produces
@RequestScoped
@MyAnnotation
private MyObject produce(InjectioPoint ip){
....
}
Let's imaging that what you'd like to do is possible. You have an @ApplicationScoped
bean defined:
@Produces
@ApplicationScoped
String produceMyString(InjectionPoint ip) {}
And you have two injection points for that bean:
@Inject
String myString1;
@Inject
String myString2;
As the bean is ApplicationScoped
, the producer method will get called only once. Which leads to the conclusion that it is impossible as the container cannot choose what injection point to use as a parameter of the producer method.
This explains why accessing the InjectionPoint
metadata forces the bean to be @Dependent
. Stated another way, the CDI specification forbids that behavior because it leads to a contradiction and not because of an arbitrary choice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With