We use Singletons a lot, and we use Stage.PRODUCTION with singletons to ensure services are created and registered, and listeners are wired together, etc... While this may not be the "best" use of Singleton, it works really well. The downside, though, is that it removes the ability to mark something as a non-eager singleton. Eager construction is a problem when you want super-fast startups (which, well, you always want if you care about startup time).
Creating @LazySingleton is easy enough. Just a new annotation and a Scope implementation that delegates to Scopes.SINGLETON (it doesn't need to delegate, but it's easier to). See: @LazySingleton: http://tinyurl.com/cbvw5e MoreScopes.LAZY_SINGLETON: http://tinyurl.com/d5asxh It works, but it's kind of frustrating that you still need to inject Provider<Foo> if you want Foo to continue to be lazy. So, to fix that, I made LazyBinder. It works on the same principal as AssistedInject -- you bind to a Provider that LazyBinder creates, and internally it creates a Proxy that delegates to the real Provider & gets the underlying object only when a method is called. LazyBinder ensures that you're creating a proxy only for an @Singleton or @LazySingleton, because otherwise it would make no sense (creating a new object for each method call). LazyBinder: http://tinyurl.com/ck7k2c If this is useful to anyone, feel free to use it. Or, if anyone has suggestions, please offer them. Sam --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
