> > 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/28bd2d98-192a-48f4-9207-d7f6612c14c8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
