xiaodududu / google-guice

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

Unexposed bindings in PrivateModules cannot be overridden via Modules.override(...) #528

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
For test we'd like to override some bindings inside a PrivateModule with 
Modules.override(...) this will only work if you expose the binding - otherwise 
it'll throw an exception.

The attached testcase reproduces the behaviour

1) A binding to java.lang.String annotated with 
@com.google.inject.name.Named(value=PRIVATE_INPUT) was already configured at 
com.google.billing.test.customerbuilder.service.PrivateModuleOverrideTest.config
ure(PrivateModuleOverrideTest.java:47).
  at com.google.billing.test.customerbuilder.service.PrivateModuleOverrideTest.provideInput(PrivateModuleOverrideTest.java:64)

1 error
        at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:402)
        at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:164)
        at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:116)
        at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:101)
        at com.google.inject.Guice.createInjector(Guice.java:105)
        at com.google.inject.Guice.createInjector(Guice.java:76)
        at com.google.inject.Guice.createInjector(Guice.java:63)
        at com.google.billing.test.customerbuilder.service.PrivateModuleOverrideTest.testPrivateBindingOverride(PrivateModuleOverrideTest.java:42)

Original issue reported on code.google.com by thoma...@google.com on 22 Jul 2010 at 7:22

Attachments:

GoogleCodeExporter commented 9 years ago
I don't think it will ever be possible to private bindings if Modules.override 
is called on a module that also installs a private module.... but I think 
something should be possible for your example (where you're calling 
Modules.override on a PrivateModule itself).

How should the nuances be handled?  Should the result be a PrivateModule also?  
Should only the same keys be exposed, or should the override module allow new 
keys to be exposed?  Should the override module be required to also be a 
PrivateModule (or be required *not* to be one)? (And any other questions you 
can think of..)

Original comment by sa...@google.com on 22 Jul 2010 at 11:43

GoogleCodeExporter commented 9 years ago
fixed in r1195.  please take a minute to review the changes @ 
http://code.google.com/p/google-guice/source/detail?r=1195 .

Original comment by sberlin on 1 Aug 2010 at 4:03