Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ensure resources are released using Google Dagger 2

Google Dagger 2 is all about object scopes e.g. when you need objects just during an http request you annotate your provider methods with @RequestScope.

But some provided resources need to be released for example a CloseableHttpClient needs to be closed or an ExecutorService needs to be shutdown.

How can I specify which actions have to be taken in order to release an object when it goes out of scope using Google Dagger 2?

like image 830
ooxi Avatar asked Jul 01 '15 07:07

ooxi


1 Answers

How can I specify which actions have to be taken in order to release an object when it goes out of scope using Google Dagger 2?

You can't. Dagger 2 is about providing dependencies to create your objects, not about managing them.

If you have objects that need to be stopped or shut down you will still have to use your components life cycle methods—like activities onDestroy—to do so.

like image 50
David Medenjak Avatar answered Oct 02 '22 08:10

David Medenjak