You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug bind extension method of BeanDefinition is not type-safe and can lead to runtime error, though it could be checked in compile-time in some cases.
To Reproduce
importorg.koin.core.context.GlobalContextimportorg.koin.core.context.startKoinimportorg.koin.dsl.bindimportorg.koin.dsl.moduleimportorg.koin.test.check.checkModulesfunmain() {
val module = module {
single { "the_string" }.bind<Int>()
}
checkModules {
modules(module) // this won't help
}
startKoin {
modules(module)
}
val koin =GlobalContext.get()
println(koin.get<String>())
println(koin.get<Int>()) // ClassCastException
}
Expected behavior
It would be great to move such errors to compile-time.
Koin project used and used version: koin_version = "2.2.2"
Possible solution
Type-safety may be achieved by using the following declaration, that specifies the base type explicitly:
Describe the bug
bind
extension method ofBeanDefinition
is not type-safe and can lead to runtime error, though it could be checked in compile-time in some cases.To Reproduce
Expected behavior
It would be great to move such errors to compile-time.
Koin project used and used version:
koin_version = "2.2.2"
Possible solution
Type-safety may be achieved by using the following declaration, that specifies the base type explicitly:
But there is a
bind
method, that doesn't takeKClass
argument and I didn't found yet an easy way to make it safe.We can make the following:
But the usage of this in verbose:
So this improvement is the subject for discussion.
I can make PR, if this solution will find support from community.
The text was updated successfully, but these errors were encountered: