-
Notifications
You must be signed in to change notification settings - Fork 580
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
Config injection happens too soon #650
Comments
If I understand correctly, your issue, rephrased, is basically something like this: our portable extension evaluates which That makes sense in general; while we create far too many producers of But, it looks also like our portable extension validates injection points at Thanks for using Helidon MP and for your report. |
Taking some notes here. The MicroProfile Config specification often leaves some things up to interpretation. In this case, the only validation guidance we get is kind of a double negative. The javadocs for This means, though, that we must not simply gather injection points via the seemingly obvious So we need to instead track However, that still doesn't get us all the way there as it is possible to, for example, have a The problem here is that the Then at Finally, at I should be able to make progress here relatively quickly. |
@ljnelson Would it make sense to create some utility classes so that we can reuse this logic in other CDI extensions in Helidon? The metrics extension, as an example, also observes |
Yes, if using the utility class in a portable extension is not more work than just doing the work in a portable extension. One way or the other we need to ensure this kind of logic is used throughout Helidon wherever it touches CDI. |
Taking more notes…. The current extension installs a lot of beans. But because Specifically, IMHO the extension should:
It would be far better to have fewer beans. Dependent producers can acquire a reference to the current From within a custom
…where That The net effect is that there should be one bean per set of qualifiers (taking into account It is also easy enough while we're doing this to "get out of the way" of any user-supplied beans that indicate they want to produce this information; we should function as defaults. |
…tion points (#708) Partially addresses #650. Signed-off-by: Laird Nelson <[email protected]>
This gets more complicated every day. CC:ing @martin-sladecek. I've refactored the internals of our CDI portable extension to ensure first of all that only non-vetoed-beans' injection points are processed. And I've changed our validation routine to make use of CDI's internal injection point resolution mechanics instead of doing it ourselves. These are both changes that needed to be made anyway. Now I'm at a place where I can write a unit test. In my first pass, I put together a test exactly as described, viz. an It turns out, after a conversation with Matěj Novotný that there is no way to determine whether an alternative is selected until actual runtime, i.e. long after the Workarounds obviously include supplying default values in the To help, I went a step or two further: suppose your alternative is actually a specializer, i.e. you have two beans, |
It now occurs to me that specialization won't help either for at least two reasons:
It is looking more and more like there is no solution to this problem, provided that the Microprofile Config specification actually mandates validation during the However, even if we are able to get away with not doing |
Thanks @ljnelson for detailed examination. What about Specialization with constructor injection - wouldn't that skip validation of the injected objects in the superclass? |
Hi, @martin-sladecek; there may be some edge cases, but the general problem goes like this: Consider Obviously the easiest workaround to this specification issue is to either (a) use The MicroProfile Config project (and its issue board) can be found here: https://github.com/eclipse/microprofile-config/ |
@martin-sladecek I'm going to close this as there's not anything more to be done on this end. Feel free to file a new issue if you discover any other problem here. |
Environment Details
Problem Description
When using
@Alternative
bean (probably also applies to CDI bean specialization), the Config injection attempt in ConfigCdiExtension happens before@Alternative
bean is evaluated, so the original bean is also instantiated and the Configs are injected into it. This is undesired as the original bean might use configuration that is not present in the current environment, leading to an exception.Steps to reproduce
@Alternative CDI
bean with higher priority to any existing beanThe text was updated successfully, but these errors were encountered: