I have a class that I want to inject which has a constructor that receives one parameter (Context).
I would normally bind it to an instance, but this class has JNI dependencies and I can not instantiate it using Robolectric, which is preventing me from testing the part of the app when the module in configured.
I have set it up as binding to the class and I have annotated the target class as singleton and also the constructor as inject, but it does not construct a factory for it.
I'll be happy to provide my own factory, but I can't find anything about that on the documentation.
This is the part when I do the binding:
val module = Module()
module.bind(Interface::class.java).to(InterfaceImpl::class.java)
scope.installModules(module)
And this is the way I have set up the class:
@Singleton
class InterfaceImpl : Interface {
@Inject
constructor(applicationContext: Context) {
[...]
}
}
Just to be clear, if I use toInstance when I do the binding it does work.
val module = Module()
module.bind(Interface::class.java).toInstance(InterfaceImpl(context))
scope.installModules(module)
How can I get the injected constructor working to bind it to the class?