Replies: 3 comments
-
I have just run into this, maybe somebody knows the solution? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yes, there is effectively no guarantee of order to close components. It could be a new feature. Need to define from where we would like to close things |
Beta Was this translation helpful? Give feedback.
0 replies
-
Please take a look at #2020 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there a way how to change order in witch the onClose methods of components are called?
Lets have two services where the latter is dependent of the former:
val appModule = module {
single { Database() } onClose {it?.closeConnectionPool()}
single { ServiceUsingDb(get()) } onClose {it?.useDatabaseForCleanup()}
}
Database component maintains a connection to some DB and the second component accesses the DB through the first component. The "ServiceUsingDb" needs to have DB available in onClose method. As the "ServiceUsingDb" is actually dependent on "Database" I would expect Koin to ensure the right closing order.
I made some research in the Koin code and if I understand it well, the components (instances, mappings) are stored in HashMap, means no specific order is guaranteed. In my case, it may (and does) happen that when ServiceUsingDb onClose is called, the DB is already closed and the cleanup fails.
Have I missed anything? Is there any way how to influence the onClose methods order?
Beta Was this translation helpful? Give feedback.
All reactions