Get/Inject all beans of T as Set<T> or List<T>
See original GitHub issueFor 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:
- Created 5 years ago
- Reactions:24
- Comments:18 (7 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Why was this closed? This feature is essential in a mature DI framework. Spring has had this feature for years.
@blundell : Exactly. Now you can do something like: