question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get/Inject all beans of T as Set<T> or List<T>

See original GitHub issue

For certain use cases I’d like to register multiple beans of SomeInterface and then get them from koin as a Set<SomeInterface> or List<SomeInterface>.

For example:

interface Command {
    ...
}

class GitClone(...) : Command {
    ...
}

class GitPull(...) : Command {
    ...
}

val ctxt = applicationContext {
    bean("clone") { GitClone(...) }
    bean("pull") { GitPull(...) }
}

fun main(args: Array<String>) {
    val koin = startKoin(listOf(ctxt))
    val cliFramework = CliFramework()
    cliFramework.registerCommands(
        koin.koinContext.getAll<Command>())
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:24
  • Comments:18 (7 by maintainers)

github_iconTop GitHub Comments

13reactions
vojtapolcommented, Nov 9, 2019

Why was this closed? This feature is essential in a mature DI framework. Spring has had this feature for years.

12reactions
REPLicatedcommented, Jan 30, 2020

@blundell : Exactly. Now you can do something like:

single { FooBarJob(get()) } bind Job::class
getKoin().getAll<Job>()
Read more comments on GitHub >

github_iconTop Results From Across the Web

Inject list of all beans with a certain interface - Stack Overflow
In case of a Collection or Map dependency type, the container autowires all beans matching the declared value type.
Read more >
Spring - Injecting Collections - Baeldung
The Spring container injects the individual beans of the BaeldungBean type into one collection. To test this, we invoke the collectionsBean.
Read more >
Inject Collection of Beans in Spring - amitph
A tutorial on Injecting Collections of Bean References of same type in Spring. Learn to Auto wire beans of same type as a...
Read more >
Spring: injecting lists, maps, optionals and getBeansOfType ...
Now we can inject List<StringCallable> , Set<StringCallable> or even Map<String, StringCallable> ( String represents bean name) to any other ...
Read more >
How to inject List into spring bean? - Java2Novice
How to inject List into spring bean? ; 17. 18. 19. 20. package com.java2novice.beans;. import java.util.List; ; <beans xmlns= "http://www.springframework.org/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found