I'm a touch confused, but maybe that's irrelevant. If you're creating the target instances through guice, you can inject your dependencies directly into them. I suspect you know this, and that there is another reason you're using member injection.
If these instances are not being created through guice, you can request injection onto them using Binder::requestInjection() ( http://google-guice.googlecode.com/svn/trunk/javadoc/index.html?com/google/inject/spi/package-summary.html ) If neither of these solutions work, could you please work backwards and elaborate on the lifecycle of the target instances onto which you need to inject dependencies? On Mon, Jan 25, 2010 at 9:13 AM, eric <[email protected]> wrote: > Thank you for the answer, but it seems to me that your solution will > not work as required... > > I want to "inject" stuff into my classes, but I don't want to call an > "injectoStuffInto(this)" for everyone and each class in my project, > this is simply NOT injection. > > My classes that needs such injection are already annotated with my own > tag "@InjectMyStuff", therefore I already know I have to > "injectStuff" in it, and it works already, using TypeListener. > > But the injectfStuff function use "Class.newInstance" (the javabean > standard) method to allocate "stuff". I just want to move to > injector.getInstance() instead, but I can't get my hands on a decent > injector while in the TypeListener (or anywhere else). > > maybe with spi ? > > > > > > On Jan 25, 1:58 pm, Fred Faber <[email protected]> wrote: > > inject Injector, not MyOwnInjector. > > > > On Jan 25, 2010 7:46 AM, "eric" <[email protected]> wrote: > > > > Hi, > > > > I've got a problem that I can't solve by myself with guice, a little > > help would be nice, thanks. > > > > I've got a routine, that injects some "stuff" from a resource into a > > given instance. Until now, the stuff that was injected was > > instanciated using "newInstance". That was nice, but now I'm getting a > > guice-addict, I would like to instanciate this "stuff" using > > injector.getInstance(). > > > > 1/ solution could be : > > > > Use a TypeListener, > > > > public void injectMembers(T t) { > > LOG.info("injecting guice/jformdesigner: " > + > > t.getClass()); > > myOwnInjector.injectInto(t); > > } > > } > > > > but myOwnInjector should have been instantiated by guice, And I can't > > make it !? > > > > 2/ a one liner in every class could go like this > > > > @Inject > > MyClass(MyOwnInjector in){ > > in.injectInto(this); > > > > } > > > > But, hey, that's a ugly dependency, isn't it ? > > > > Any ideas ? > > > > -- > > 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]> > <google-guice%2bunsubscr...@google groups.com> > > . > > For more options, visit this group athttp:// > 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]<google-guice%[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.
