I agree, LazyBinder is an extension much like AssistedInject and doesn't
really belong in core Guice.  Though if AssistedInject were to go in, you'd
hear no complaints from me.

Lazy singletons in Stage.PRODUCTION, on the other hand, I think could have a
place.  Consider a binding like @Singleton(lazy=true), or
bind(Foo.class).in(Scopes.LAZY_SINGLETON) (which would would like
Names.named, returning a new @Singleton instance to bind to that had
lazy=true set) -- this would be no different than the current Singleton
bindings, except with the added feature that the Singleton would be lazily
instantiated even if Stage.PRODUCTION was true.

I'm actually not sure right now if Guice could even support something like
@Singleton(lazy=true).  Is the ScopingAnnotation passed to the Scope
implementation?  That might be something that you want to consider adding.
Even if a lazy singleton isn't your cup of tea, I can imagine there could be
other scopes where parameters to the scoping annotation might want to
trivially effect the way its scoped.

Sam

On Wed, Apr 8, 2009 at 8:34 PM, [email protected] <[email protected]> wrote:

>
> Sam, this is very nice work.
>
> Lack of support for lazy singletons in Stage.PRODUCTION is a Guice
> weakness. I'm curious if this is a general problem, or one that only
> comes up when singletons are used aggressively for initialization,
> like in your app. We don't have them in our apps at Google and so far
> there hasn't been much complaining. But we're writing server-side
> apps, where eager initialization and slow start-up aren't major
> concerns.
>
> I particularly like how you're using aggressive scope checks in
> LazyBinder.registerAndCheckTypes(). The compareAndSet() call is also
> handy to ensure you only get a single instance. Nice work.
>
> I'm semi-reluctant to include all of this is in core Guice, because I
> find that dynamic proxies can cause confusion in debugging I have the
> same problem with EasyMock. I'm also anxious about the tradeoffs
> between lazy instantiation (great!) and proxying everything (not so
> great!).
>
> For now, I've posted a link here from our Scopes wiki:
>
> http://groups.google.com/group/google-guice/browse_thread/thread/e34e475609c2cec4
>
> Cheers,
> Jesse
>
> PS - I admit that I'm a horrible hypocrite for giving dynamic proxies
> much love in AssistedInject.
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to