Hello,

I'm having a similar problem. I have classes that are being used by
the 'robot', its 'legs' and its 'toes'. I'm using children of the
'robot' Injector for the legs and children of the 'leg' Injectors for
the 'toes'. One of these classes uses an injected Injector. Objects
created with this injector should have bindings available to get the
'robot', 'leg' or 'toe' in which they exist. Since this class is also
used by the 'robot', the Injector seems to use the parent (or
grandparent) Injector to create instances for the the child modules
and that is the one that ends up getting injected. A quick search for
"child injector" in this group turns up a post from last August where
Dhanji suggested binding the Injector using a provider. I'm not sure
this would work since the 'right leg' doesn't actually know it's the
'right leg' but apparently declaring a binding of an Injector is not
legal in the Guice 2.0 jar that is currently in central maven anyway.

Has anyone gotten something like this working?

Thanks,

Grandin Hammell

On Mar 25, 6:49 am, martinp <[email protected]> wrote:
> Hi,
>
> I have used Guice now for several months and have found it incredibly
> productive to work with.
>
> However I have run into a problem, which is  variation on the 'robot
> legs' problem I suppose.
>
> I have a set of objects forming part of an application, that function
> as a module. A number of those objects must be Singletons and
> I have scoped them as such in the Module declarations.
>
> However I now need to be able to run multiple instantiations of the
> module with different configuration parameters. I am currently working
> on the premise that I needchildinjectors.
>
> This involves havingchildinjectors that contain more global scope
> and thenchildinjectors from those injectors. Like configuring the
> 'toes' in the 'robot legs' ! There is also the requirement that extra
> instantiations are generated on-the-fly at runtime.
>
> There are a couple of types of object that needs to be singletons in
> each instance of the  injector, so one instance in each 'leg' and one
> instance in each 'toe'. I have not been able to work out how to
> achieve this. If I declare it a singleton in the leginjector, then I
> cannot get new singletons in the toes. Since these graphs are
> generated at runtime I cannot use @Named or have different subclasses.
>
> Does anyone have ideas on how I can achieve my goal.
>
> Regards,
>
>    Martin Pike

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