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):

http://google.github.io/guice/api-docs/latest/javadoc/com/google/inject/Binder.html#bindListener-com.google.inject.matcher.Matcher-com.google.inject.spi.TypeListener-

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)

http://google.github.io/guice/api-docs/latest/javadoc/com/google/inject/Binder.html#bindListener-com.google.inject.matcher.Matcher-com.google.inject.spi.ProvisionListener...-

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:

https://github.com/google/guice/wiki/CustomScopes
> 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 <[email protected]>:
> > > > 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.  
> > > >  
> > > >  
> > >  
> > >  
> > >  
> >  
> >  
> >  
>  
>  
>  
>  
> --  
> 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] 
> (mailto:[email protected]).
> To post to this group, send email to [email protected] 
> (mailto:[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/4da7cf82-b95f-44e7-8c02-e6e81e0cc1ea%40googlegroups.com
>  
> (https://groups.google.com/d/msgid/google-guice/4da7cf82-b95f-44e7-8c02-e6e81e0cc1ea%40googlegroups.com?utm_medium=email&utm_source=footer).
> For more options, visit https://groups.google.com/d/optout.

-- 
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/0D1BA6C584F94AAABA48C5296DF5220B%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to