When I use interface like below in viewmodel
class MainViewModel @ViewModelInject constructor(
private val trafficImagesRepository: TrafficImageRepository, <----------------- Not working
@Assisted private val savedStateHandle: SavedStateHandle
) : ViewModel()
I am getting an error like below
cannot be provided without an @Provides-annotated method.
public abstract static class SingletonC implements MainApplication_GeneratedInjector,
My interface is like below
interface TrafficImageRepository {
suspend fun getTrafficImages() : NetworkResponse<TrafficData, ErrorTrafficImages>
}
And Repository class is like below
class DefaultTrafficImagesRepository @Inject constructor(private val trafficImageService: TrafficImageService) : TrafficImageRepository {
override suspend fun getTrafficImages(): NetworkResponse<TrafficData, ErrorTrafficImages> {
lateinit var response: NetworkResponse<TrafficData, ErrorTrafficImages>
withContext(IO) {
val currentTimestamp = Constants.getCurrentTime()
response = trafficImageService.getTrafficImages(currentTimestamp)
}
return response
}
}
But when I use DefaultTrafficImagesRepository class directly instead of Interface my app is able to build without any error.
class MainViewModel @ViewModelInject constructor(
private val trafficImagesRepository: DefaultTrafficImagesRepository , <----------------- Working Fine
@Assisted private val savedStateHandle: SavedStateHandle
) : ViewModel()