InsertKoinIO / koin

Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform
https://insert-koin.io
Apache License 2.0
8.76k stars 695 forks source link

String parameter is injected by default as empty string even when there is no string declaration in a koin module #1894

Open adrianczuczka opened 2 weeks ago

adrianczuczka commented 2 weeks ago

Describe the bug I'm not sure if this is a bug or not and I'm sure I'm not the first to notice this, but it's about string parameters. If a class has a string parameter in the constructor, I would expect the DI to fail if there is no string parameter provided in any koin module, but instead it succeeds. As mentioned in other threads, I believe this is because if there is no adequate dependency in any module, koin defaults to an empty string? Please let me know if this makes sense or if more context is needed.

To Reproduce

  1. Go to Android Studio and create a sample project with Koin as a dependency
  2. Create a class with a string parameter in the constructor, such as:
    class Test(private val testString: String)
  3. Create a koin module which provides the class but not a string parameter:
    val testModule = module {
    singleOf(::Test)
    }
  4. Create a test which calls koinApp.checkModules()

Expected behavior Expected behavior would be for the koin test to fail because there is no string dependency provided in any koin module, but instead it succeeds.

Koin module and version: koin-android:3.4.3 koin-android-test:3.4.3

csanfilippo commented 5 days ago

It happens also to me