> > 1) The provider will create the service once when get() is called, and I > guess I will have to cache it somewhere since it's a relatively heavy task. > My provider then looks like a lazy singleton.
You can combine Provider and @Singleton, so Guice takes care of the caching (I'm unsure of where the annotation should go). 2) I am not sure how I can control where the first call to get() will > occur, so I don't have a clear place to catch initialization errors Just directly after the createInjector call? Or place it anywhere you want and use an unchecked exception as you wan't forget to catch it, will you? Just as you say, I'd rather have badly configured services blowing up > immediately on application startup, That's what Stage <http://google.github.io/guice/api-docs/latest/javadoc/com/google/inject/Stage.html> can be used for (pass it to createInjector <http://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/Guice.html> as the first argument). Or use EagerSingleton <http://code.google.com/p/google-guice/issues/attachmentText?id=38&aid=7525098890798343689&name=EagerSingleton.java&token=048967455f3d1853e58ac98e6d7e3b7c> . -- You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-guice. To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/CAGsWfGgB7Z3aNv1oJ3dvTbS5o7ztiAkTfMdXY7-76BLC-vnFKA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
