InsertKoinIO / koin-annotations

Koin Annotations - About Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform insert-koin.io
https://insert-koin.io
Apache License 2.0
123 stars 30 forks source link

There is no way to declare onClose callback for Koin declaration #87

Open Pschsch opened 1 year ago

Pschsch commented 1 year ago

Is your feature request related to a problem? Please describe. To declare onClose callback, I should decline from using koin annotations and use pure Koin DSL

Describe the solution you'd like Add annotation @OnCloseAction. It must b applied to object declaration with corresponding function. For example:

@OnCloseAction
object OnCloseAction {

    /*If there are no onClose function, throw an error*/
    fun onClose(value : Any?) {

    }

}

And in actual definition:

@[Single OnClose(action = OnCloseAction::class)]
class Definition {

}

OnCloseAction annotation could be also applied to whole module, so action will be executed for every module declaration

Describe alternatives you've considered Maybe there would be better solutions

Target Koin project koin-annotations

arnaudgiuliani commented 11 months ago

Yes, good point. It's not available yet.

We could also annotate a function to let call it on onClose, with a @OnClose from an annotated entity:

@Single
MySingle( val myDep : MyDep ) {

    @OnClose
    fun oncLose(){

    }
}
alturkovic commented 4 months ago

Is there any target version when this might be available?

arnaudgiuliani commented 3 months ago

for now it's a proposal, checking feasibility and impact on APIs. Seems doable for 1.4

arnaudgiuliani commented 6 days ago

perhaps duplication with #112