In my case, I have a BaseViewModel which all viewModels inherit from this class. I want to add a base repo to the base view model by field injection. Injecting by constructor does not work in my case because I have to provide that repo to all viewModels inherited from baseViewModel too. I am doing like this:
open class BaseVM @Inject constructor() : ViewModel() {
@Inject
lateinit var sampleRepo: SampleRepo
fun test(): String {
return sampleRepo.test()
}
}
but I get this error
lateinit property sampleRepo has not been initialized
this is my module:
@Module
@InstallIn(SingletonComponent::class)
interface SampleModule {
@Binds
fun bindSampleRepo(repoImpl: SampleRepoImpl): SampleRepo
}