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

Viewed 685

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

2 Answers

The provideShowsScheduleRepository method should be placed in a module class (by saying that I mean a class annotated with @Module). Are you sure that this module is installed in the correct scope? If not, try adding @InstallIn(SingletonComponent::class). (You can replace SingletonComponent with any other component that is described here based on your needs)

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

Related