Discussion:
Can I Inject x Class?
Joe DeSantis
2018-06-20 20:45:44 UTC
Permalink
I was working with a JUnit 5 extension for Guice, and we had the need to
determine if a particular class was able to be injected by an injector.
The only solution we came up with is attempting to get an instance with
that Injector. (Literally calling the getInstance method, in a try/catch
block).
So my question is simply, what is the best way of determining if you can
get an instance of a particular class given an injector.

The discussion on the implementation is here for anyone who is curious,
https://github.com/JeffreyFalgout/junit5-extensions/commit/adf2f4ece977e834ba9b4f1563ebc568784ad3a4#commitcomment-29425765

Thanks!
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/dbbc0674-7e82-47de-97ee-6bdf9258d2fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2018-06-21 06:51:24 UTC
Permalink
Jukito takes another approach. They use an ElementVisitor to collect all
bindings and then decide if the required binding is in the module(s).
Have a look at the BindingsCollector.java class

https://github.com/ArcBees/Jukito/blob/master/jukito/src/main/java/org/jukito/BindingsCollector.java
Post by Joe DeSantis
I was working with a JUnit 5 extension for Guice, and we had the need
to determine if a particular class was able to be injected by an
injector.
The only solution we came up with is attempting to get an instance
with that Injector. (Literally calling the getInstance method, in a
try/catch block).
So my question is simply, what is the best way of determining if you
can get an instance of a particular class given an injector.
The discussion on the implementation is here for anyone who is curious,
https://github.com/JeffreyFalgout/junit5-extensions/commit/adf2f4ece977e834ba9b4f1563ebc568784ad3a4#commitcomment-29425765
Thanks!
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/dbbc0674-7e82-47de-97ee-6bdf9258d2fd%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/dbbc0674-7e82-47de-97ee-6bdf9258d2fd%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/c98854df-a81a-7053-c32a-692dde254fc9%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Luke Sandberg
2018-06-21 13:59:46 UTC
Permalink
Injector.getBinding is probably the right method
Post by Stephan Classen
Jukito takes another approach. They use an ElementVisitor to collect all
bindings and then decide if the required binding is in the module(s).
Have a look at the BindingsCollector.java class
https://github.com/ArcBees/Jukito/blob/master/jukito/src/main/java/org/jukito/BindingsCollector.java
I was working with a JUnit 5 extension for Guice, and we had the need to
determine if a particular class was able to be injected by an injector.
The only solution we came up with is attempting to get an instance with
that Injector. (Literally calling the getInstance method, in a try/catch
block).
So my question is simply, what is the best way of determining if you can
get an instance of a particular class given an injector.
The discussion on the implementation is here for anyone who is curious,
https://github.com/JeffreyFalgout/junit5-extensions/commit/adf2f4ece977e834ba9b4f1563ebc568784ad3a4#commitcomment-29425765
Thanks!
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/dbbc0674-7e82-47de-97ee-6bdf9258d2fd%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/dbbc0674-7e82-47de-97ee-6bdf9258d2fd%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/c98854df-a81a-7053-c32a-692dde254fc9%40gmx.ch
<https://groups.google.com/d/msgid/google-guice/c98854df-a81a-7053-c32a-692dde254fc9%40gmx.ch?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/CAO9V1MJbM8TpBj8k38Fhn4%3DgTUq8gWxhfaPKP5%3D4-23VgOW6wg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Joe DeSantis
2018-06-21 14:30:24 UTC
Permalink
The method that was used prior was: injector.getExistingBinding(key)).
isPresent()
It did accurately identify all explicit bindings, however it did not work
with just-in-time bindings.
Post by Luke Sandberg
Injector.getBinding is probably the right method
Post by Stephan Classen
Jukito takes another approach. They use an ElementVisitor to collect all
bindings and then decide if the required binding is in the module(s).
Have a look at the BindingsCollector.java class
https://github.com/ArcBees/Jukito/blob/master/jukito/src/main/java/org/jukito/BindingsCollector.java
I was working with a JUnit 5 extension for Guice, and we had the need to
determine if a particular class was able to be injected by an injector.
The only solution we came up with is attempting to get an instance with
that Injector. (Literally calling the getInstance method, in a try/catch
block).
So my question is simply, what is the best way of determining if you can
get an instance of a particular class given an injector.
The discussion on the implementation is here for anyone who is curious,
https://github.com/JeffreyFalgout/junit5-extensions/commit/adf2f4ece977e834ba9b4f1563ebc568784ad3a4#commitcomment-29425765
Thanks!
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/dbbc0674-7e82-47de-97ee-6bdf9258d2fd%40googlegroups.com
<https://groups.google.com/d/msgid/google-guice/dbbc0674-7e82-47de-97ee-6bdf9258d2fd%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an
<javascript:>.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/c98854df-a81a-7053-c32a-692dde254fc9%40gmx.ch
<https://groups.google.com/d/msgid/google-guice/c98854df-a81a-7053-c32a-692dde254fc9%40gmx.ch?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/8fc1fe40-8b87-4985-a2c3-680707754cac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...