I'll second what Colin wrote and additionally point out that your best bet is:
class Foo {
private final Provider<MyClass> myClassProvider;
@Inject
Foo(Provider<MyClass> myClassProvider) {
this.myClassProvider = myClassProivder;
}
public void bar() {
MyClass myClass = myClassProvider.get();
....
}
}
specifically, strongly prefer constructor injector over member
injector (think about how you'd test in either case to see why).
-Fred
On Thu, Jun 24, 2010 at 7:25 AM, Nicolas ANTONIAZZI
<[email protected]> wrote:
> Hi,
>
> it might seems to be a stupid question, but what is exactly the
> difference between :
>
> public class Foo {
> �...@inject
> private Injector injector;
>
> public void bar() {
> MyClass c = injector.inject(MyClass.class);
> }
> }
>
> and :
>
> public class Foo {
> �...@inject
> private Provider<MyClass> myClassProvider;
>
> public void bar() {
> MyClass c = myClassProvider.get();
> }
> }
>
>
> What is the best to use ?
>
> --
> 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.
>
>
--
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.