6

Does Koin provide the functionality of binding several dependencies into a collection, as Dagger does with multibindings?

Let's suppose I have this interface:

interface Initializer: (Application) -> Unit

And this interface has several implementations, for instance:

class LoggingInitializer: Initializer {
    override fun invoke(p1: Application) {
        Timber.plant(Timber.DebugTree())
    }
}

The implementations are provided in different modules using bind modifier:

val coreToolsModules = module {
    single { LoggingInitializer() } bind Initializer::class
}

And such modules are installed in the app's Application class:

class TestApplication: Application() {

    override fun onCreate() {
        super.onCreate()
        val startKoin = startKoin {
            logger(PrintLogger())
            androidContext(this@TestApplication)
            modules(listOf(coreToolsModules))
        }
    }
}

I'd like to inject all implementations of Initializer class as a set to my Application class in order to carry out such initialization:

    val initializers: Set<Initializer> by inject()

    //in onCreate()
    initializers.forEach { it.invoke(this) }
Mehul Kabaria
  • 6,404
  • 4
  • 25
  • 50
Stanislav Shamilov
  • 1,746
  • 11
  • 20
  • https://stackoverflow.com/questions/54374067/how-to-retrieve-all-instances-that-matches-a-given-type-using-koin-dependency-in – gtxtreme Aug 02 '22 at 07:40

0 Answers0