frjaeger220 / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Modules.override() should be more granular #312

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I define two modules: ModB overrides ModA.

ModA: 
    bind(A.class).to(AImpl.class).in(Singleton.class);

ModB: 
    bind(A.class).to(AImpl2.class);

When I call injector.getInstance(A.class) multiple times, I always have
different instances.

I think this should result in a singleton instance of AImpl2.class.

The same is when you define an implementation in ModA and define only a
scope in ModB.

ModA:
    bind(A.class).to(AImpl.class);

ModB:
    bind(A.class).in(Singleton.class);

This should result in a Singleton version of AImpl and not of A (assuming A
is a class, not an interface)

What should be great is that only what is defined in the overriding module
really overrides something defined in the overriden module.

Original issue reported on code.google.com by ogregoire on 16 Jan 2009 at 10:59

GoogleCodeExporter commented 9 years ago
Interesting. We're not going to do it because I think it could be quite 
surprising, especially when you throw into 
the mix that some types have scoping annotations on 'em. What we want to do is 
be able to say that for each 
binding, you can look at a specific line of source to see where it was defined. 
If we supported this it would be 
composed.

The workaround is straightforward — change the binding in ModB to specify 
Singleton.class.

Original comment by limpbizkit on 26 Jan 2009 at 1:26

GoogleCodeExporter commented 9 years ago
Okay, fair enough!

Original comment by ogregoire on 26 Jan 2009 at 10:14