How can I manage the life cycle of a managed entity in a dagger column

I see no support for lifecycle management in a dagger. Only DI, and nothing for @PostConstruct or @PreDestroy.

I would like Dagger to start / stop the object, this is a graph in the same way as Spring. How can i do this?

+4
source share
2 answers

The life cycle of objects on the graph coincides with the life cycle of the graph itself. As soon as the graph receives garbage collection, so are all objects inside the graph.

I do this by creating subgraphs in a dagger. Subgraphite will contain all objects (single points inside this graph) that require a shorter life cycle. System-wide objects fall into the main schedule, on which the subgraph depends.

PS. I am not familiar with Spring, so I cannot explain how this relates to Spring.

+1
source

Opened https://github.com/google/dagger/issues/455 to find out if this is planned or will never be realized. @ Alex-Collins solution (workaround?) Via LifeCycleManager and explicit register () in the dagger module .

0
source

Source: https://habr.com/ru/post/1497598/


All Articles