I think a global switch like .lazilyLoadSingletons() would be better for prod mode. OR, which is much simpler and requires no changes to Guice: create a new scope called @LazySingleton
Dhanji. On Tue, Sep 16, 2008 at 7:23 AM, Sam Berlin <[EMAIL PROTECTED]> wrote: > > Hi Folks, > > We're using the Registry-style approach to lifecycle-management (among > other things). This means we need to mark the class that does the > registration as a singleton and that we need to either > a) Use Stage.PRODUCTION in the Injector > or > b) Bind it as an eagerSingleton. > > I'm personally very much against b) because it separates the knowledge > between two classes, the implementation and the Module. That seems > confusing to me -- requiring that you have to navigate to two classes > to make sure the instance is registered appropriately. > > a) works very well, but has a minor drawback that all @Singletons are > now eagerly loaded. This isn't a terrible thing in and of itself, but > sometimes you want to use a Singleton because it's a Singleton, not > because it needs to be loaded early. > > So, I propose two solutions, both of which I'll be glad to code up > myself -- I'd just like to get some feedback from folks and see if > this is a desired feature. > > Proposal One: @Singleton(eager=true) -- forces the Singleton to be > loaded eagerly. It would act exactly the same as .asEagerSingleton(), > except that the information about the binding is where @Singleton is > listed, not where the binding is done. (This is only useful, of > course, if the @Singleton annotation is being used. If binding is > done using in(Scopes.SINGLETON), then asEagerSingleton would still be > the preferred method.) > > Proposal Two: @Singleton(lazy=true) -- forces the Singleton to be > lazily loaded, even if Stage.PRODUCTION is used. This has no current > analogue (and I don't propose any, but if anyone has suggestions I'm > all ears). This would be used when you really don't to eagerly load > the singleton, for any reason. > > I'd actually like two implement both, with it being an error-condition > if both eager & lazy are true. Any thoughts? > > 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 -~----------~----~----~----~------~----~------~--~---
