-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Hello,
I'm working on adding kotlin-inject-anvil to a new KMP project.
Similar to this issue, I'm trying to understand how I can have an interface in one module (say :domain) and an implementation in another (say :data). A parent module (say :parent) contains :domain and :data.
I want it so that if consumers include :parent that they automatically have injectable implementations of the items in it's :domain without seeing the implementations in :data.
:domain
interface MyDataSource {
fun getThing(): String
}
:data (includes :domain dependency)
@ContributesBinding(AppScope::class)
@SingleIn(AppScope::class)
class MyDataSourceImpl @Inject constructor() : MyDataSource {
override fun getThing(): String = "a string"
}
However when I try to create a component in :parent:
@MergeComponent(AppScope::class)
@SingleIn(AppScope::class)
abstract class CoreComponent {
abstract val myDataSource: MyDataSource
}
it says that Cannot find an @Inject constructor or provider for MyDataSource, though I've defined it on MyDataSourceImpl via @ContributesBinding. I tried using @Provides the way typically done using plan kotlin-inject, but it's no difference.
Oddly enough though, this seems to only affect iosArm64 and iosSimulatorArm64 - I'm able to get it to work on JVM/Android with a bit of fiddling around.
So I guess my questions are:
- Am I just fundamentally misunderstanding how
@ContributesBindingworks or are there limitations around having it in different modules? - Is my understanding of how to use
kotlin-injectandkotlin-inject-anvilin KMP incorrect?
I've followed the documentation both here and here as well as looked at the samples provided in both this repo and kotlin-anvil.