On Tuesday, October 8, 2013 4:56:47 AM UTC-4, kumar santosh wrote: > 1. I have class AModule where we are binding are the dependencies. > > 2. In class Test i created Instance of B using Injector. like . > Injector in = Guice.createInjector(new AModule()) > // getting instance of B > in.getInstance(B); > > 3. I am in same jvm, In some other class D, can i get instance of some > class "C" without again calling Guice.createInjector(new AModule()) >
Two ways: - Create D using the injector, and have B injected into it (this is pretty much *the* thing Guice is good for) - Pass a reference to the injector from Test to D. If there is no connection between B and D at all, maybe there is some code which instantiates both of them? I hesitate to say "put the injector into a static field" since that's exactly the pattern Guice exists to eliminate, but if it's test code and there's really *no* other way, it would work. But I'd say reconsider your design if that looks like the way you have to do it. -Tim -- You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-guice. For more options, visit https://groups.google.com/groups/opt_out.
