Comment by [email protected]:

To clarify a few things, it might help to look at Guice this way. You can either have Guice construct your class for you, via injector.getInstance(YourClass.class), or you can construct the class "manually", for example YourClass y = new YourClass(.....), or maybe JUnit is doing it for you.

If Guice constructs the class for you, it scans the class for @Inject annotations, from top to bottom, fields first, then methods. For each field marked @Inject, it will try to create an instance of that field using injector.getInstance(FieldClass.class). Then, for each method, it will call that method, and any arguments are injected again using injector.getInstance(ArgumentClass.class). Finally, Guice returns to you the newly created instance.

If, however, Guice does NOT create the class for you, then you must explicitly tell it to inject all the @Inject-annotated things by calling injector.injectMembers(instance).

Note that with any @Inject-annotated thing, you can also give it an additional @Named("name") or @SomeOtherAnnotation annotation to choose a specific instance. That has to do with bindings.

There's more information about the order of injection here: http://code.google.com/p/google-guice/wiki/InjectionPoints

I hope that clears up a few questions, because it sure as heck helped me :)

For more information:
http://code.google.com/p/google-guice/wiki/Injections

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" 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-dev?hl=en.

Reply via email to