Hi Rodrigo,
I did some more testing.
1) If Stage is Stage.PRODUCTION, the Provider's get() method actually
gets called
when Guice.createInjector(Stage.PRODUCTION, ...) is called.
binder.bind(TestClass.class).toProvider(new Provider<TestClass>() {
public TestClass get() {
return new TestClass();
}
}).in(Scopes.SINGLETON);
private static TestClass
{
TestClass() { // let's say construction takes a long
time... };
}
So, if TestClass() takes a long time to construct, then
Guice.createInjector(..) will take a long time to return.
2) Suppose the setup is the same as case 1 except now I remove the
Singleton scope, Provider's get() does not get called when
Guice.createInjector(..) is called. Hence, the createInjector(..)
method returns quickly.
3) createInjector(..) also returns quickly when Stage is DEVELOPMENT.
Provider's get() also does not get called.
So, my question is, why does 1) behave the way it does? Why does the
Provider's get() gets called when
Guice.createInjector(Stage.PRODUCTION, ...) is called? I understand
that the Provider's constructor will be called but why the get()
method also?
I would think that the Provider's get() gets called when I actually
invoke it. When I put Scopes.SINGLETON, I thought it
means that the Provider is a singleton. Am I correct?
Thanks, Grace
On Oct 1, 9:30 am, "Rodrigo M. do Prado" <[EMAIL PROTECTED]>
wrote:
> Hi Grace,
>
> could you attach the entire source code of the provider that you've
> implemented?
>
> Tks, Rodrigo
>
>
>
> On Wed, Oct 1, 2008 at 12:36 AM, Grace <[EMAIL PROTECTED]> wrote:
>
> > Hi all,
>
> > It takes less than 1/2 sec to create the injector when I only have
> > bindings from interfaces to regular classes.
>
> > But once I bind provider,
>
> > public class VehicleProvider implements Provider<IVehicle>{
>
> > }
>
> > binder.bind(IVehicle.class).toProvider(VehicleProvider.class).in(Scopes.SINGLETON),
>
> > it takes more than 10 secs to create the injector.
> > How come there is such great difference? If I care about speed,
> > should I avoid using provider?
>
> > Thanks, Grace
>
> --
> Rodrigo M. do Prado
> [EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---