Thursday, February 3, 2011

Re: Gin, SingleInstanceProvider?

if you do not want your objects to be in Singleton scope,
just use Provider in following fashion.
no configuration is necessary.

public class MyClass {

private final Provider<Foo> fooProvider;

@Inject
public MyClass(Provider<Foo> fooProvider){
this.fooProvider = fooProvider;
}

public void myMethod(){

Foo foo = fooProvider.get(); // this result in on-demand instantiatin of Foo.
                              
                                          // injecting Provider<Foo> in the constructor
                                         // does not result in instantiation of Foo.
     
                                         // later, when myMethod is invoked, only at that point
                                         /// with the call to .get() , foo instance is created

}

}

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate