On Thursday, 14 May 2015 at 10:50, klc wrote:
So my questions are:
1. Is there a way to find out if a guice has been created?
Previously in Guice 3 you could use a TypeListener to track when objects were directly instantiated by Guice (this doesn’t cover objects constructed inside of providers):
In Guice 4 you can also use the new ProvisionListener API to track when objects are provisioned (ie. either instantiated by Guice itself or returned from a provider)
but you might have to do some de-duplication here since the same object could be provisioned multiple times.
Another approach is to use a custom scope to record object use - you can then add a close method to the scope and call it when you want to dispose of those objects:
2. Is there a way to let guice to run deconstruct when server is closing? (ie ServletContextListener.contextDestroyed)
Assuming you’ve got a record of the objects needing to be destroyed (using one of the methods above) then it’s mainly a matter of going through the list in reverse order and calling the right destroy method.
klc
On Thursday, May 14, 2015 at 5:34:02 PM UTC+8, klc wrote:
Sorry
What i have now is a provider of let say a queue (Singleton scope). If the queue has been created, i will get from the injector and close it. (or is there a way to do this automatically?)
This is on guice-servlet.
klc
On Thursday, May 14, 2015 at 5:31:20 PM UTC+8, scl wrote:
Yes, but you have to be more specific if you want some concrete help
Am 14. Mai 2015 11:25:52 MESZ, schrieb klc <
klchan...@gmail.com>:
Hi Is there a way to destruct object in guice 4?
I see guice fruit but i think it support guice 2. The object i'm closing are db, queue and etc.