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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With