It sounds like you may be misunderstanding child injectors. A child
injector inherits all bindings from its parent injector, but not the other
way around. Here's an overview of what I think you need to do:

- Create an injector (settingsInjector) with all the bindings required by
your other modules that need injection. So for example, the bindings
required for AppSettingsService.
- Use settingsInjector.getInstance to get instances of the modules that
need injection.
- Use settingsInjector.createChildInjector to create a child injector,
passing it those modules and any others it needs.
- Return that child injector from ServletModule#getInjector(). It will have
all of your bindings.

Nothing in this scenario should cause the error you mentioned either, I
don't think. That sounds like something caused by trying to create a
binding in a parent injector that already existed in a child injector...
probably caused by a private module.

-- 
Colin


On Thu, Feb 23, 2012 at 4:21 PM, Warren Bell <[email protected]> wrote:

> I have tried different combinations of modules and child injector
> before. I have gotten it to work in one application, but not this one.
> This is a guice servlet app and in ServletModule#getInjector() you can
> only return one Injector and I do not end up with any access to the
> bindings created in the child injector.
>
> I have also gotten the following error before:
>
> Unable to create binding for com.MyClass. It was already configured on
> one or more child injectors or private modules.
>
> I have tried so many different scenarios that I have forgotten what
> scenario created this error. I basically gave up on the child injector
> solution thinking it would just not work with Guice Servlet.
>
> Thanks,
>
> Warren Bell
>
> On 2/23/12 12:55 PM, Colin Decker wrote:
> > If you need to do more complex configuration, you could use a child
> > injector approach (or even just two completely separate injectors if you
> > won't need the bindings from the injector used for the settings service
> > again after creating the second injector). What are the problems you've
> run
> > in to with that approach?
> >
>
> --
> 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.
>
>

-- 
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