I think you're looking for assisted inject: http://code.google.com/p/google-guice/wiki/AssistedInject
On Fri, Jul 8, 2011 at 7:25 AM, ich du <[email protected]> wrote: > it is probably a general DI question but i guess i am not in wrong place. > > i just make my first guice steps and i begin to like it, but i just > stumbled on refactoring a non DI constructor to DI-style here is a general > example: > > before DI > > public class MyClass { > private C1 c1 = new C1impl(); > private C2 c2 = new C2impl(); > private SomeClass parameter; > public MyClass(SomeClass parameter){ > this.parameter =parameter; > ... > } > ...} > > after DI: > > public class MyClass { > private C1 c1; > private C2 c2; > private SomeClass parameter; > @Inject > public MyClass(SomeClass parameter, C1 c1, C2 c2){ > this.parameter =parameter; > this.c1=c1; > this.c2=c2; > ... > } > ...} > > Without "parameter" all would be fine (to get an instance of MyClass i > would use a Provider). But how to get a provider of MyClass (i don't want > parameter to be injected but all others). > new MyClass(parameter, providerC1.get(),providerC2.get()) does not look > nice (i want to get rid of all "new"). setting "parameter" via a setter > isn't a option if MyClass relies on a non-null "parameter". So what is best > practice to solve this problem? > > thx in advance > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/google-guice/-/2abvXhxbxDYJ. > 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.
