You need to have as few or as many modules as needed to declare all items that 
are depended-upon, or asked-for from the injector

The exception is if you are using just-in-time binding and haven't forbidden 
no-arg constructors, and in that case, any object with an explicit or implicit 
no-arg constructor could be instantiated by the injector to satisfy a 
dependency.

But other than the above, yes, you must have BarDep bound in some module 
somewhere that is passed to createInjector() or install()ed in another module.

Christian.

On Jul 5, 2012, at 12:06 PM, google-gu...@googlecode.com wrote:

> Comment by zxy1256:
> 
> I have a related question: When create an injector to create Foo, do we need 
> a BarDepModule, which is a module for Bar's dependency?
> 
> {{{
> public class Foo {
>    private Bar bar;
> 
>    @Inject
>    public Foo(Bar bar) {
>        this.bar = bar;
>    }
> 
>    public static void main(String[] argv) {
>        Injector injector = Guice.getInjector(new BarModule());
>        Foo foo = injector.getInstance(Foo.class);
>    }
> }
> //=====================
> public interface Bar {}
> 
> public class BarImp {
>    private BarDep barDep; // Dependency of Bar
> 
>    @Inject
>    public Bar(BarDep barDep) {
>        this.barDep = barDep;
>    }
> }
> //=====================
> 
> }}}
> 
> For more information:
> http://code.google.com/p/google-guice/wiki/InjectOnlyDirectDependencies
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "google-guice-dev" group.
> To post to this group, send email to google-guice-dev@googlegroups.com.
> To unsubscribe from this group, send email to 
> google-guice-dev+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/google-guice-dev?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to google-guice-dev@googlegroups.com.
To unsubscribe from this group, send email to 
google-guice-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en.

Reply via email to