I can't see any support for life-cycle management in Dagger. Only DI, and nothing for @PostConstruct or @PreDestroy.
I'd like Dagger to start/stop object is the graph in the same manner Spring does. How can I do this?
The life-cylce of objects in the graph is the same as the life-cycle of the graph itself. As soon as the graph gets garbage collected, so will all objects within the graph.
I accomplish this by creating sub-graphs in Dagger. The sub-graph will contain all objects (singletons within that graph) that require a shorter life-cycle. Application-wide objects go in the main graph which the sub-graph is dependent on.
PS. I am not familiar with Spring so I can't explain how this relates to Spring.
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