Inject ViewModel using Dagger 2 + Kotlin + ViewModel

后端 未结 6 1378
-上瘾入骨i
-上瘾入骨i 2021-02-07 07:07
class SlideshowViewModel : ViewModel() {

@Inject lateinit var mediaItemRepository : MediaItemRepository

fun init() {
    What goes here?
}

So I\'m tr

6条回答
  •  别那么骄傲
    2021-02-07 07:44

    Try with below code :

    @Provides
    @Singleton
    fun provideRepository(): Repository {
        return Repository(DataSource())
    }
    

提交回复
热议问题