No value found error when confirmed created before injection
Describe the bug
I am working on a multiplatform project primarily focusing on Android at the moment. In commonMain, I have an interface IHttpClientFactory that has an implementation defined in androidMain. A function getHttpClientFactory is marked as expected with an actual definition in androidMain.
In my module, I define a singleton for IHttpClientFactory, calling the getHttpClientFactory fun. Another singleton for an IInventoryManager (impl HttpInventoryManager which takes an IHttpClientFactory as a paraneter).
When the HttpInventoryManager is created by koin, and exception occurs stating that there is no value for IHttpClientFactory.
To Reproduce Steps to reproduce the behavior:
- Have or create an KMP project with Android as a target
- Create an interface in commonMain with an expect function to get an instance of interface
- Implement interface in androidMain and create actual of function to get instance
- Define module in commonMain and add
singlefor interface, calling the expect function to provide instance - Define class in commonMain with constructor param of above interface, add to module as single
- Use
koinInjecton step 5 interface somewhere in Android app - Run application
Expected behavior
The implementation instance that is created for koin should be provided as a value for IHttpClientFactory.
Koin module and version:
- koin-compose: 4.1.0
Snippet or Sample project to help reproduce
COMMON MAIN Inventory Module
val inventoryModule = module {
single<IHttpClientFactory>(createdAtStart = true) {
getHttpClientFactory()
}
single<IInventoryManager> {params-> HttpInventoryManager(params.get()) }
}
Http Client Factory
interface IHttpClientFactory {
fun createClient(): HttpClient
}
expect fun getHttpClientFactory(): IHttpClientFactory
Injection
class HttpInventoryManager(private val httpClientFactory: IHttpClientFactory): IInventoryManager
ANDROID MAIN Http Client Factory
class OkHttpClientFactory(): IHttpClientFactory {
override fun createClient(): HttpClient {
return HttpClient(OkHttp)
}
}
actual fun getHttpClientFactory(): IHttpClientFactory = OkHttpClientFactory()
Root of stack:
org.koin.core.error.InstanceCreationException: Could not create instance for '[Factory: 'com.bigballard.tool.inventory.InventoryItemViewModel']'
...
Caused by: org.koin.core.error.InstanceCreationException: Could not create instance for '[Singleton: 'com.bigballard.tool.inventory.IInventoryManager']'
...
Caused by: org.koin.core.error.DefinitionParameterException: No value found for type 'com.bigballard.tool.http.IHttpClientFactory'
...