Ok, I think I know what I was doing wrong. I never added the child
injector to my app. I thought the child injector was contained in the
parent injector, but after looking at some of the Guice tests I realized
you could create more than one Injector instance, a parent and children
and children of children and so on.

I did this:

Injector parentInjector = Guice.createInjector(getModule1());
injector.createChildInjector(getModule2());

thinking all I needed was parentInjector when I should of done this.

Injector parentInjector = Guice.createInjector(getModule1());
Injector childInjector = injector.createChildInjector(getModule2());

Let me know if I have missed any thing else.

Thanks,

Warren Bell

On 1/11/12 2:47 PM, Warren wrote:
> I have seen many posts on this, but I still do not know or understand
> how to fix it. I am getting the following error:
> 
> Problem getting itemsGuice configuration errors: 1) Unable to create
> binding for ...ItemService. It was already configured on one or more
> child injectors or private modules bound at ... bound at ... If it was
> in a PrivateModule, did you forget to expose the binding? while
> locating ...ItemService 1 error
> 
> Code:
> 
> Injector injector = Guice.createInjector(getModule1());
> injector.createChildInjector(getModule2());
> 
> 
>       private static Module getModule1()
>       {
>               return new PrivateModule()
>               {
>                       @Override
>                       protected void configure()
>                       {
>                                bind(AppSettingsService.class);
>                                expose(AppSettingsService.class);
>                       }
>               };
>       }
> 
>       private static Module getModule2()
>       {
>               return new PrivateModule()
>               {
>                       @Override
>                       protected void configure()
>                       {
>                                bind(ItemService.class);
>                                expose(ItemService.class);
>                       }
>               };
>       }
> 
> And there is only one @Inject anotation in this test app at:
> 
>       @Inject
>       private ItemService itemService;
> 
> ItemService and AppSettingsService are empty classes.
> 
> What am I missing ?
> 
> Thanks,
> 
> Warren Bell

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to