1 | initial version |
To use Hilt for injecting a list into a ViewModel, you can follow the below steps:
@Module
@InstallIn(SingletonComponent::class)
object MyModule {
@Provides
fun provideMyList(): List<MyObject> {
// return your list of objects
}
}
@HiltAndroidApp
class MyApp : Application()
@Inject
annotation to your ViewModel constructor:class MyViewModel @Inject constructor(private val myList: List<MyObject>) : ViewModel() {
// use the injected list in your ViewModel logic
}
Hilt will automatically instantiate your ViewModel and inject the list of objects into its constructor.