koin icon indicating copy to clipboard operation
koin copied to clipboard

Nullable parameter injection crash

Open romanandreyvich opened this issue 2 years ago • 3 comments

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

romanandreyvich avatar May 26 '22 02:05 romanandreyvich

Is it q feature request for nullable injected param?

arnaudgiuliani avatar Jun 27 '22 14:06 arnaudgiuliani

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) }

andersu avatar Jun 29 '22 08:06 andersu

DSL Constructor doesn't support nullable param for now. We need to investigate more about that.

arnaudgiuliani avatar Jul 18 '22 06:07 arnaudgiuliani

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.

stale[bot] avatar Dec 15 '22 11:12 stale[bot]