Laurent Martelli
2014-11-07 15:30:54 UTC
If you have a child injector and ask the parent injector a value for a binding defined in the child, you get an "It was already configured on one or more child injectors" error.
It would be better to say "No implementation for ... was bound, although it is configured in a child injector".
Here's a sample code:
```java
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
public class GuiceBug {
public static void main(String[] args) {
Injector i1 = Guice.createInjector();
Injector i2 = i1.createChildInjector(
new AbstractModule() {
@Override
protected void configure() {
bind(IStuff.class).to(Stuff.class);
}
});
i1.getInstance(IStuff.class);
}
static interface IStuff {}
static class Stuff implements IStuff {}
}
```
```
Exception in thread "main" com.google.inject.ConfigurationException: Guice configuration errors:
1) Unable to create binding for org.enercoop.test.GuiceBug$IStuff. It was already configured on one or more child injectors or private modules
bound at org.enercoop.test.GuiceBug$1.configure(GuiceBug.java:15)
If it was in a PrivateModule, did you forget to expose the binding?
while locating org.enercoop.test.GuiceBug$IStuff
1 error
at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1004)
at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:961)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1013)
at GuiceBug.main(GuiceBug.java:18)
```
---
Reply to this email directly or view it on GitHub:
https://github.com/google/guice/issues/877
It would be better to say "No implementation for ... was bound, although it is configured in a child injector".
Here's a sample code:
```java
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
public class GuiceBug {
public static void main(String[] args) {
Injector i1 = Guice.createInjector();
Injector i2 = i1.createChildInjector(
new AbstractModule() {
@Override
protected void configure() {
bind(IStuff.class).to(Stuff.class);
}
});
i1.getInstance(IStuff.class);
}
static interface IStuff {}
static class Stuff implements IStuff {}
}
```
```
Exception in thread "main" com.google.inject.ConfigurationException: Guice configuration errors:
1) Unable to create binding for org.enercoop.test.GuiceBug$IStuff. It was already configured on one or more child injectors or private modules
bound at org.enercoop.test.GuiceBug$1.configure(GuiceBug.java:15)
If it was in a PrivateModule, did you forget to expose the binding?
while locating org.enercoop.test.GuiceBug$IStuff
1 error
at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1004)
at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:961)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1013)
at GuiceBug.main(GuiceBug.java:18)
```
---
Reply to this email directly or view it on GitHub:
https://github.com/google/guice/issues/877
--
You received this message because you are subscribed to the Google Groups "google-guice-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice-dev+***@googlegroups.com.
To post to this group, send email to google-guice-***@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice-dev.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "google-guice-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice-dev+***@googlegroups.com.
To post to this group, send email to google-guice-***@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice-dev.
For more options, visit https://groups.google.com/d/optout.