I have a question about Android HIlt. I have an An...
# dagger
a
I have a question about Android HIlt. I have an Android module which provides APIs so basically a bunch of interfaces. Like
Copy code
interface Paying {
    fun pay(amount: Double)
}
I have a separate module in which the implementation for above interface lies
Copy code
class Purchase @Inject constructor() : Paying {
    override fun pay(amount: Double) {
        // Implementation logic here
    }
}
The impl module has following binding between interface and implementation class
Copy code
@InstallIn(SingletonComponent::class)
@Module
abstract class PayingModule {

    @Binds
    abstract fun bindPayingApi(impl: Purchase): Paying
}
Doing above I am getting the error
cannot be provided without an @Provides-annotated method
If I move the interface and implementation in the same module, then error resolves. Does anyone know how can I fix this.
d
Copy code
@Binds
abstract fun bindPayingApi(impl: Purchase): Paying
a
You still need to annotate
Purchase
with
@Singleton
a
Nope, that doesn't work
f
Since you said in the same module, that means that both of your modules need hilt dependencies if you decide to spread them