How to inject abstract class I have an abstract class
abstract class FactoryMediator : xx, yy,zz {}
I am trying to initiate the object for this class using @Module and @Binds annotations. But that is failed to create and throw an error.
@Module
@InstallIn(SingletonComponent::class)
abstract class PolicyModule {
@Binds
abstract fun bindFactoryMediator(factoryMediator: FactoryMediator): PolicyFactoryMediator
}
But this is giving error. What mistake I did? Please can you let me know how to create for abstract class. How can we inject abstract class? From documentation, it says. Sometimes a type cannot be constructor-injected. This can happen for multiple reasons. For example, you cannot constructor-inject an interface. You also cannot constructor-inject a type that you do not own, such as a class from an external library. In these cases, you can provide Hilt with binding information by using Hilt modules.
A Hilt module is a class that is annotated with @Module. Like a Dagger module, it informs Hilt how to provide instances of certain types. Unlike Dagger modules, you must annotate Hilt modules with @InstallIn to tell Hilt which Android class each module will be used or installed in.