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

CDI.current().select(Foo.class).get() does not work if Foo is not injected #2576

Closed
ah1508 opened this issue May 23, 2019 · 12 comments
Closed
Labels
area/arc Issue related to ARC (dependency injection) kind/enhancement New feature or request
Milestone

Comments

@ah1508
Copy link

ah1508 commented May 23, 2019

CDI.current().select(...).get() is useful to get a bean whose type is known dynamically, with quarkus it only works if the type is injected somewhere.

For example :
Foo foo = CDI.current().select(Foo.class).get() causes a javax.enterprise.inject.UnsatisfiedResolutionException

Problem solved with

@Inject Foo foo;

even if foo is not used.

If it is due to build time optimizations, how about an option to flag the classes (here Foo) to register theses beans even if not injected anywhere ? Something like a retention policy.

@ah1508 ah1508 added the kind/enhancement New feature or request label May 23, 2019
@kenfinnigan
Copy link
Member

@mkouba can confirm but I'd say it's because the class is being removed because ArC can tell it isn't needed

@Dufgui
Copy link
Contributor

Dufgui commented May 23, 2019

I would like to fix this

@geoand
Copy link
Contributor

geoand commented May 24, 2019

A while back I had proposed something in between removing all unused and not removing any unused beans at all. The idea was to keep all beans defined in the application - see this.

Perhaps it's something we should reevaluate? If it is something that we think makes sense, then I can redo the PR.

Another idea might be to add some kind of nnotation that will ensure that Arc never removes the bean?

@mkouba
Copy link
Contributor

mkouba commented May 24, 2019

@kenfinnigan I confirm.

@Dufgui This optimization can be disabled using quarkus.arc.remove-unused-beans=false. See https://quarkus.io/guides/cdi-reference#remove_unused_beans.

@geoand I like both of your ideas. Actually, I've been thinking of the annotation for a long time. It could be just @Unremovable. WRT keep app beans - it could be a special "mode", so that we could reuse the quarkus.arc.remove-unused-beans property. So we could have the following modes: all/true, framework (keep app beans), none/false.

@mkouba mkouba added the area/arc Issue related to ARC (dependency injection) label May 24, 2019
@geoand
Copy link
Contributor

geoand commented May 24, 2019

@mkouba @Unremovable sounds perfect!

I can implement both of these two proposals in the following days (probably won't have any spare time today) if you agree.

@mkouba
Copy link
Contributor

mkouba commented May 24, 2019

@geoand of course! ;-)

@Dufgui
Copy link
Contributor

Dufgui commented May 24, 2019

thanks for your reply. Yes i see the remove unused flag (in the code, not in the doc ;o) )
I just try the approach to keep the optimization. But as I really like the @Unremovable idea.

geoand added a commit to geoand/quarkus that referenced this issue May 25, 2019
This is one part of the solutions discussed in quarkusio#2576
geoand added a commit to geoand/quarkus that referenced this issue May 25, 2019
This is one part of the solutions discussed in quarkusio#2576
geoand added a commit to geoand/quarkus that referenced this issue May 25, 2019
This is one part of the solutions discussed in quarkusio#2576
geoand added a commit to geoand/quarkus that referenced this issue May 25, 2019
This is one part of the solutions discussed in quarkusio#2576
geoand added a commit to geoand/quarkus that referenced this issue May 27, 2019
This is one part of the solutions discussed in quarkusio#2576
geoand added a commit to geoand/quarkus that referenced this issue May 27, 2019
This is one part of the solutions discussed in quarkusio#2576
geoand added a commit to geoand/quarkus that referenced this issue May 27, 2019
This is one part of the solutions discussed in quarkusio#2576
geoand added a commit to geoand/quarkus that referenced this issue May 27, 2019
This is one part of the solutions discussed in quarkusio#2576
@geoand
Copy link
Contributor

geoand commented May 27, 2019

@mkouba Now for the second part of proposed solution, how would you like to handle the quarkus.arc.remove-unused-beans value? Currently that value is a boolean but we would like to make it an Enum I guess. That would mean breaking existing applications that define this configuration.
What do you propose we do?

@mkouba
Copy link
Contributor

mkouba commented May 27, 2019

Could we just use a string and map it to the following modes?

Mode Values
all all, true
framework (keep app beans) fwk
none none, false

@geoand
Copy link
Contributor

geoand commented May 27, 2019

That sounds interesting. It wouldn't break existing applications (unless I am missing something) and we could support all the required modes.

Sounds good! I'll take it up soon 😉

geoand added a commit to geoand/quarkus that referenced this issue May 27, 2019
geoand added a commit to geoand/quarkus that referenced this issue May 27, 2019
geoand added a commit to geoand/quarkus that referenced this issue May 27, 2019
geoand added a commit to geoand/quarkus that referenced this issue May 27, 2019
@geoand
Copy link
Contributor

geoand commented May 28, 2019

@mkouba should we close this now with that we have a couple related solutions in place?

@mkouba
Copy link
Contributor

mkouba commented May 28, 2019

@geoand Yes ;-).

@mkouba mkouba closed this as completed May 28, 2019
@gsmet gsmet added this to the 0.16.0 milestone Jun 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants