On 20 August 2010 16:16, dg <[email protected]> wrote: > > I don't know a direct way in Guice to do this. However, depending on > the structure of your objects, you might be able to get away with > something like this > > class MyModule implements Module { > [snip] > @Provides > provide MasterBean( ContextBean ctx, OtherDep dep ) { > return new MasterBean( new SubBean1( ctx ), new SubBean2( ctx ), > otherDep ); > } > } > > It's not ideal, but... >
you could also use the AssistedInject extension to pass on the context to the sub beans while still using Guice to inject them for complex graphs another solution is to use child injectors: http://stackoverflow.com/questions/3014140/dependency-injection-scoping-by-region-guice-spring-whatever HTH -d > > On Aug 18, 7:43 am, Olli <[email protected]> wrote: > > Hi, > > > > I'm struggling with injecting one instance into two different beans. > > > > Here is my bean structure: > > > > - MasterBean > > - SubBean1 > > - SubBean2 > > > > MasterBean get both SubBean's injected, the SubBean's does not know > > each other. > > Both SubBeans get's one ContextBean instance injected. > > > > The scope of the ContextBean should be attached to the MasterBean, so > > when I create a new MasterBean, two new SubBean's should be created > > and one ContextBean which is being injected into the two SubBeans. > > > > Using a singleton is not really a solution because it limits the > > MasterBean to one instance. Another solution would be an additional > > Guice-Scope, but this a little bit overkill I think... :-( > > > > Any ideas how to solve this? > > > > Regards, > > Oliver > > -- > 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]<google-guice%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-guice?hl=en. > > -- Cheers, Stuart -- 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.
