Open alturkovic opened 7 months ago
It seems you want all bindings that implement a Closeable
interface to act as onClose { it?.close}
automatically.
How would you differentiate a Closeable
binding that is provided in Koin that (1) should be closeable by Koin onClose
from (2) one that should not be closed by Koin, such as one associated with androidx ViewModel.addCloseable
?
I have no experience on Android, I was comparing the behaviour of Closeable
beans in Spring. When shutting down a Spring application, all beans implementing Closeable
are being closed, like having an implicit onClose { it?.close}
call. I have not encountered a scenario where I implemented a Closeable
interface that was handled as a singleton that I did not want to be closed on shutdown, so I am not familiar with the Android handling :/
Really need this feature too. Adding onClose callbacks manually is not sweet.
It seems you want all bindings that implement a
Closeable
interface to act asonClose { it?.close}
automatically.How would you differentiate a
Closeable
binding that is provided in Koin that (1) should be closeable by KoinonClose
from (2) one that should not be closed by Koin, such as one associated with androidxViewModel.addCloseable
?
This is a very good point. What about a dedicated interface, let's say org.koin.core.Closeable
, or maybe org.koin.core.Disposable
? This way it would be an explicit intent.
Is your feature request related to a problem? Please describe. I have a lot of beans which implement the
Closeable
interface. It would be nice if koin could destroy these beans on shutdown automatically instead of having to usesingle { MyBean } onClose { it?.close() }
Describe the solution you'd like Have koin call
close()
on allCloseable
beans on shutdown.Describe alternatives you've considered Support a new callback when destroying beans so I could do something similar to:
Target Koin project core