Hi all is it possible to register shutdown hooks o...
# koin
v
Hi all is it possible to register shutdown hooks on beans created by koin? During my application shutdown I'd like to some of my beans to have a method invoke to clean up resources
a
no shutdown hook in current 2.0 beta
you need to be notified before closing resources?
v
Yes, as part of lifecycle management
let me give you a real example
During startup we create google cloud pubsub subscriptions for services
when application stops we should delete those resources
I come from Spring (as developer and committer) and it's one thing I'm missing in koin at the moment
Another thing I noticed is that the ktor extension does not really calls the stop
which seems to be possible by listening to ktor events
so when someone kills the server, it bubbles up events that koin context could close the context, and therefore invoke any resource "destroy" functions
a
@Vinicius Carvalho yeah sure, please open a feature proposal for 2.0 👍
a way to hook on koin shutdown if I understand well
v
Sure I'll open two feature requests, see if they make sense 🙂
So I opened two issues
the destroy one could be a
destroy: T.()->Unit
function that is passed to the factories, and during closing they could invoke it
I honestly have not look too much inside koin code, but I'd assume that a dependency graph would take care of the order of which components are destroyed