public interface Vehicle { }public static class Car implements Vehicle { }public static void main(String[] args) {Injector injector = Guice.createInjector(new AbstractModule() {@Overrideprotected void configure() {bind(Vehicle.class).to(Car.class).in(Singleton.class);bindListener(Matchers.any(), new ProvisionListener() {@Overridepublic <T> void onProvision(ProvisionInvocation<T> provision) {System.out.println(provision.getBinding().getKey() + " is singleton = " +Scopes.isSingleton(provision.getBinding()));}});}});injector.getInstance(Vehicle.class);}
Key[type=com.instinet.gtr.cucumber.caas.di.TestGuice$Car, annotation=[none]] is singleton = false
bind(Vehicle.class).to(Car.class);
bind(Car.class).in(Singleton.class);
(I don't know listeners much so can't really help beyond the above)
Hi Thomas,
Thanks for taking the time to reply. The output posted is the total output from my test.
Therefore, Guice is only observing one provision. Thus, its not like theres a second provision I could inspect.
Also, the modules I'm consuming are provided by application developers who use my framework. I've published in the API they need to produce Guice modules. I'm not willing to be more restrictive and tell them to use specific syntax, that would reflect poorly on my framework.
If the two separate bindings do work, this surely suggests a Guice bug? As far as I can tell your two-liner should be functionally equivalent to my on-liner?
I'll try the two-liner tomorrow. My intention would be to debug + raise a bug / pull request if it actually fixes the underlying problem... Unless someone can explain the disparity between the one/two-liner?
Thanks again!
--
You received this message because you are subscribed to a topic in the Google Groups "google-guice" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-guice/c2Gt_ABD7cQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-guice...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/b0d87ebc-b473-4b1b-97da-ec85f5755b5a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Also, the modules I'm consuming are provided by application developers who use my framework. I've published in the API they need to produce Guice modules. I'm not willing to be more restrictive and tell them to use specific syntax, that would reflect poorly on my framework.
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 http://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/CACyC%2BgJXxxM%3Dk-i10dDyxROigYPv_Dm_72_qT7GqBP5Y3pnfxw%40mail.gmail.com.
Will output:bind(Vehicle.class).to(Car.class);bind(Car.class).in(Singleton.class);
Key[type=com.instinet.gtr.cucumber.caas.di.TestGuice$Car, annotation=[none]] is singleton = true
AbstractModule mod = new AbstractModule() {
@Overrideprotected void configure() {bind(Vehicle.class).to(Car.class).in(Singleton.class);}
};Elements.getElements(mod).forEach((e) -> {e.acceptVisitor(new DefaultElementVisitor<Void>() {public <T> Void visit(Binding<T> binding) {if (Scopes.isSingleton(binding)) {System.out.println(binding.getKey() + " is singleton = " + Scopes.isSingleton(binding));}return null;}});});
Key[type=com.instinet.gtr.cucumber.caas.di.TestGuice$Vehicle, annotation=[none]] is singleton = true
The lack of notification for linked bindings is by design. ProvisionListener only notifies things that are provisioned (essentially the right hand side of any linked binding).
This does have a bad side effect of dropping some scoped notifications, though, and folks probably aren't expecting that. I had thought it was mentioned in the javadocs, but looks like it isn't.
At the very least, I can mention it in the docs. I'm less enthused about notifying on linked bindings too, but maybe that's not so terrible.
sam
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/18c94b93-299b-4bd4-88cd-dff3c56d44c9%40googlegroups.com.