-
Notifications
You must be signed in to change notification settings - Fork 77
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
CDI instance injection ordering #478
Comments
@starksm64 since you brought it up again, do you have any specific use case for this? Just wondering. BTW I think Weld has something similar implemented as part of |
It came up on the Quarkus developer list regarding a problem with ordering of a security provider instance. |
Is this issue still relevant even after introduction of the |
It seems to me that indeed the So I'd be +1 to closing this. |
I agree. However I wanted to hear from @starksm64 since he created the issue and maybe we're missing something :) |
I stumbled upon this again in the context of smallrye/smallrye-reactive-messaging#1856, where they are adding their own notion of [message] interceptors and want them ordered according to priority (ideally in the same way CDI orders interceptors according to priority :-) ). I mentioned above that an Am I missing something? |
Yes, due to various ways in which you can define beans getting priority is no easy feat. |
FTR ArC has the |
So I'm mostly thinking about ordering, which was the original purpose of this issue. Enablement is a different kind of thing and not enabled beans don't even make it to Iteration order of
In all cases, an additional question is how to order beans that have no priority value. (The comparator in Weld currently treats them as priority value of |
Zero is fine if higher priority goes first which is IMO more intuitive (and both |
I only pointed it out because you can effectively get enabled alternative without any priority attached to it and it is still valid.
Why not highest to lowest? Then you can keep zero for enabled beans without numeric value on priority. |
If CDI has to process multiple things in priority order (interceptors, decorators, is there anything else?), lower priority values always come before higher priority values. Indeed Weld and ArC sort from higher to lower, which is IMHO unfortunate. |
For alternatives and ambiguous names the beans with the highest priority values are taken. Interceptors with lower priority values are called first which effectively means that interceptors with higher priority values are "closer" to the the target method invocation and thus can affect the "context", e.g. change the call arguments and override the arguments set by interceptors with lower priority values. So the semantics is IMO a bit disputable.
I disagree. |
What's unfortunate about that?
+1 |
Right. There are basically 2 contexts where priority matters:
I take it you argue that iterating over alternatives in priority order is different from applying interceptors/decorators because there's nothing being "wrapped", but I just see an unnecessary inconsistency and confusion. |
But you don't need to wrap anything in case of injecting multiple beans. It's a different use case. |
Not really, you actually do both based on whether you are looking at the ordering prior to "wrapped" method invocation or post the invocation.
Actually the opposite, I think it is very similar in that the highest priority has the most "power" in terms of controlling/affecting the actual "wrapped" method based on being invoked immediately before/after the method itself. |
Linking to this previous
https://issues.redhat.com/browse/CDI-535
Description
We should allow ordering of bean instance injection using the Instance when an instance injection is used.
The text was updated successfully, but these errors were encountered: