Hi, I have following scenario - rather usual use of Singletons which I'd like Inject with Guice.
There is StatsService which is currently implemented using Singleton Pattern and has a state. I receives data from various places and sends them over separate Thread which is constantly running. This runs throughout entire lifecycle of the application. In the App there are multiple Threads executing various tasks. Each Runnable Object posts internal metrics to StatsService.getInstance().increament(1); pool = new ThreadPoolExecutor(); pool.run(new CustomTask()); Do I have to inject StatsService into a constructor of every object I create starting from Main class? Or is there a way any instance can lookup Guice Singleton Instance and use it? I could just simply inject CustomTask with StatsService instance but if CustomTask initializes some other Object which needs to have access StatsService then we need to inject the inherited objects as well - kind of a chain which I don't really like to see. What would be the correct design choice to organize code and take advantage of Singleton instance for this reporting purpose? Thanks, Vlad -- 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. For more options, visit https://groups.google.com/d/optout.
