Hi All,
I'd like to write a provision listener which is capable of identifying
instances of singletons when they're provisioned. Specifically singletons
that are bound in a module using in(Singleton.class).
However, using the helper method Scopes.isSingleton(...) does not appear to
be correctly identifying singletons bound in this fashion.
Here is a demonstration of the problem I am encountering:
public interface Vehicle { }
public static class Car implements Vehicle { }
public static void main(String[] args) {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(Vehicle.class).to(Car.class).in(Singleton.class);
bindListener(Matchers.any(), new ProvisionListener() {
@Override
public <T> void onProvision(ProvisionInvocation<T> provision) {
System.out.println(provision.getBinding().getKey() + " is singleton = " +
Scopes.isSingleton(provision.getBinding()));
}
});
}
});
injector.getInstance(Vehicle.class);
}
If I execute this I get the following console output:
Key[type=com.instinet.gtr.cucumber.caas.di.TestGuice$Car,
annotation=[none]] is singleton = false
Am I missing something? This seems to be incorrectly reporting that the
provision was not a singleton?
Any tips would be greatly appreciated.
Thanks!
P.S. Guice 4.0
--
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 [email protected].
To post to this group, send email to [email protected].
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/e0b23087-dd2a-4ae9-9b7d-3a1e15d20d10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.