Search code examples
androidkotlindependency-injectiondaggerdagger-hilt

Dagger/Hilt missing binding. Repository cannot be provided without an @Provides-annotated method


I have this interface

interface ShowsScheduleRepository {
    suspend fun getShowsSchedule(medium: String, timeSlot: String): ShowsSchedule
}

which is provided in this class

class GetShowsScheduleUseCase @Inject constructor(
    private val repository: ShowsScheduleRepository
)

by

@Provides
@Singleton
fun provideShowsScheduleRepository(api: TDRetrofitApi): ShowsScheduleRepository {
    return ShowsScheduleRepoImpl(api)
}

and then this class is injected in a viewModel

@HiltViewModel
class HomeFragmentViewModel @Inject constructor(
    private val getShowsSchedule: GetShowsScheduleUseCase
) : ViewModel() {

And when I am trying to build I get the error that it cannot provide a ShowsScheduleRepository without an @Provides-annotated method


Solution

  • Note to self: Put the AppModule file in the same Android Module where the HiltEntryPoint is