3

Dagger 2 has the ability to injecting set or map with multibindings. How to do it in Toothpick

for example i want @Inject constructor(val map: Map<String, ISyncRepository>)

Jacob
  • 81
  • 1
  • 6

1 Answers1

1

it might be like:

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

Look at the following 2 samples

https://google.github.io/dagger/multibindings.html

https://blog.kotlin-academy.com/understanding-dagger-2-multibindings-viewmodel-8418eb372848

for

@Inject constructor(

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

) 

using:

@Binds
@IntoMap
@ViewModelKey(UserViewModel.class)
abstract ViewModel bindUserViewModel(UserViewModel userViewModel);
lannyf
  • 9,865
  • 12
  • 70
  • 152