I am new to Google Guice after working a lot with Windsor Castle (.NET).
I would like to achieve in Google Guice something similar to Windsor Castle Startable Facility (http://docs.castleproject.org/Windsor.Startable-Facility.ashx).
This means that the injector will auto-create the instance of my singleton service eagerly as soon as it was binded and all dependencies are satisfied.
I would like to call a start() method on service creation, and stop() method on application shutdown. For example, start() would initialize a timer and stop() would typically cancel this timer.
I am aware of the Eager Singletons feature ".asEagerSingleton()" but I can think of few problems with it:
(1) If I do method injection in the service, the constructor of the service is called before method injected dependencies are set. Therefore I may not be able to fully use the service in the construction time.
(2) There is no auto shut-down. I have to manually get instance of the service in my application shutdown logic and call a stop() method. And worse, If I have many such services I have to manage shutdown order explicitly according to cross-dependencies.
Any suggestions?