Misleading error message with child injector
See original GitHub issueIf 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:
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)
Issue Analytics
- State:
- Created 9 years ago
- Reactions:8
- Comments:13 (4 by maintainers)
Top Results From Across the Web
[guice] Misleading error message with child injector (#877)
If you have a child injector and ask the parent injector a value for a binding defined in the child, you get an...
Read more >Crazy ChildInjector-related Exception - Google Groups
The scenario is: We create a parent injector for the core and a child injector for the UI. The child injector has an...
Read more >Re: Child injector causes Guice configuration errors - The Mail Archive
I get the same type of error > message: "It was already configured on one or more child > injectors or private modules"....
Read more >Injectors • Angular - codecraft.tv
Child injectors forward requests to their parent injector if they can't resolve the token locally. TypeScript. Copy import { ReflectiveInjector } from '@angular ......
Read more >Introduction to services and dependency injection - Angular
In Angular, dependency injection makes those services available to components. ... export class Logger { log(msg: any) { console.log(msg); } error(msg: any) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can’t help but think @laurentmartelli was right about this error.
bind
call, I get this errorbind
call, I get “No implementation for
…was bound
”How can I have too many bindings, then remove one binding, and then not have enough?
It was confusing for me as well, googling this discussion turned out the fastest way to find the actual cause, so the message could just as well have a link to this discussion.