Hello Tim,
Thanks for your answers, I really appreciate the time and effort. 
Just as you say, I'd rather have badly configured services blowing up 
immediately on application startup, eager error detection being an 
important criteria for good software imho. Honestly I admit I still haven't 
found a satisfying approach and almost got back to my hand-made, 
factory-based dependency injection. For my project, I could not afford to 
spend too much time figuring out how to combine guice with my 
non-trivial-non-named-properties-based initialization needs. I am thinking 
about using providers with unchecked exceptions but need to experiment 
first.

Kind regards

Le samedi 30 août 2014 06:38:02 UTC+2, Tim Boudreau a écrit :
>
> I thought I could do the big initialization job in my module, create the 
>> service instance and bind it to some interface so I could inject a ready to 
>> use object later during the app lifecycle. However I have learnt in the 
>> documentation that this approach is discouraged :
>> https://github.com/google/guice/wiki/ModulesShouldBeFastAndSideEffectFree
>>
>
> BTW, I generally agree with the advice there, but the reality is that 
> sometimes you need a "shutdown" lifecycle piece.  Giulius, which I linked 
> in the previous message, has something for that:
>
> http://timboudreau.com/builds/job/mastfrog-parent/lastSuccessfulBuild/artifact/giulius-modules/giulius-parent/giulius/target/apidocs/com/mastfrog/giulius/ShutdownHookRegistry.html
> which can be used to trigger logical shutdown (i.e. close connections, 
> etc.) either on VM shutdown or when Dependencies.shutdown() is called 
> (Dependencies is just a wrapper for the injector that provides a module to 
> bind @Named stuff).
>
> Logical shutdown very useful in unit tests (I wrote a JUnit extension - 
> https://github.com/timboudreau/giulius-tests - which lets you have test 
> methods with injected arguments) where you want to completely clean up the 
> environment after a test run;  I've even used it to allow an application to 
> completely unload and reload itself on a unix signal, without shutting down 
> the JVM.
>
> The bottom line for me is that the usefulness of being able to inject, 
> say, a JDBC connection, and not pollute application code with the setup of 
> it, is too valuable not to have.
>
> -Tim
>
>

-- 
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/9ecc5094-d870-447e-8ec3-3522cbd581c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to