koin
koin copied to clipboard
Nullable parameter injection crash
Describe the bug
Can't inject a nullable parameter to a dependency registered by singleOf/factoryOf.
I pass null with parametersOf(null)
and it fails with exception:
Caused by: org.koin.core.error.DefinitionParameterException: No value found for type
To Reproduce
Here is an example, I have a class:
class Foo(userId: Int?)
Register it via singleOf/factoryOf
val module = {
factoryOf(::Foo)
}
Trying to resolve:
val foo = get<Foo> { parametersOf(null) }
Got:
Caused by: org.koin.core.error.DefinitionParameterException: No value found for type
Expected behavior An instance of Foo with Foo.userId is null
Koin project used and used version (please complete the following information):
koin: 3.2.0
Is it q feature request for nullable injected param?
We also have some crashes with nullable injected params. It works fine with the old DSL, but crashes with the new DSL. So is it really a feature request or is it a bug? If the new DSL does not support it yet, I would like to request this feature indeed :)
This crashes when passing null:
viewModelOf(::HowDoesItWorkViewModel)
This does not crash when passing null:
viewModel { (earningPeriodEndDate: String?) -> HowDoesItWorkViewModel(get(), get(), earningPeriodEndDate) }
DSL Constructor doesn't support nullable param for now. We need to investigate more about that.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.