I am creating a Clean architecture + mvvm project with hilt, but i dont understand one moment of hilt work.
I have a viewModelL
@HiltViewModel
class DateViewModel @Inject constructor(
private val getWinRateByDayUseCase: GetWinRateByDayUseCase,
private val getCoordinatesByArrUseCase: GetCoordinatesByArrUseCase,
private val getDayStatisticsUseCase: GetDayStatisticsUseCase
) : ViewModel(){
ViewModel need getDayStatisticsUseCase which require TradeRepository:
class GetDayStatisticsUseCase(private val tradeRep: TradeRepository) {
fun execute(): Flow<List<Trade>> {
return tradeRep.getDayStatistic()
}
}
Trade repository implementation :
class TradeRepositoryImp @Inject constructor(private val dataSource:TradeDataSource): TradeRepository
Question :
I understand why do we need inject constuctor in viewModel but i dont really understand why we dont need it in use case but we need it in repository implementation
Why don’t we need to introduce dependencies injection into the use case?
fen fen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.