Thanks,
It seems that using a Provider throwing unchecked exceptions and manually 
calling injector.getInstance(...) right after createInjector on my 
top-level services allows me to initialize and validate my configuration on 
Startup. 
Problem solved, thanks for your help!
Best


Le mardi 2 septembre 2014 16:35:51 UTC+2, Martin Grajcar a écrit :
>
> 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/2d7cc1b3-1b38-4e08-ad50-418fedd5bba8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to