匕首2有能力注入集合或映射与多重绑定。
用牙签怎么做
例如我想要
@Inject constructor(val map: Map<String, ISyncRepository>)

最佳答案

可能是:

   @Binds
   @IntoMap
   @TheMapKey(“your key”)
   abstract fun getSyncRepository() : ISyncRepository

看下面两个样本
https://google.github.io/dagger/multibindings.html
https://blog.kotlin-academy.com/understanding-dagger-2-multibindings-viewmodel-8418eb372848
对于
@Inject constructor(

     private val creators: Map<Class<out ViewModel>, @JvmSuppressWildcards
         Provider<ViewModel>>

)

使用:
@Binds
@IntoMap
@ViewModelKey(UserViewModel.class)
abstract ViewModel bindUserViewModel(UserViewModel userViewModel);

10-07 22:18