koin-annotations
koin-annotations copied to clipboard
Add bean/module destructor for Annotation-defined bean/module
Is your feature request related to a problem? Please describe.
My bean is defined with annotation:
@Module
class AppModule {
@Single(createdAtStart = true)
fun sqlDriver() : SqlDriver {
//...
}
}
I want to define bean/module close strategy to it.
Effecitvely I want to run sqlDriver.close() during KoinApplication::close call.
Describe the solution you'd like The design might be something like this:
@Module
class AppModule {
@Single(createdAtStart = true)
fun sqlDriver() : SqlDriver {
//...
}
@OnClose
fun closeModule(sqlDriver: SqlDriver) {
sqlDriver.close()
}
}
Describe alternatives you've considered
If bean is AutoClosable the bonus design might be something like this:
@OnClose(closeAutoClosable = true)
@Single(createdAtStart = true)
fun sqlDriver() : SqlDriver {
//...
}
But conflicts resolution strategy with @OnClose and close order of dependant beans must be designed additionally.
Target Koin project Koin-Annotations
yes, definitely need to propose around closing definitions with onClose