is there a way to provide dependencies of the same...
# koin
m
is there a way to provide dependencies of the same type and inject them all together as a list? multibindings
m
+1
s
I've injected lists of dependencies, used a named parameter
not sure about the multibinding though
m
@Scott Kruse I need
koin
to recognise and group multiple objects of the same type into list and give me ability to use that list. I don’t want to create list myself
s
Why should Koin arbitrarily put objects of the same type into a list and assume you need it in this way? You need to tell Koin your dependencies. Koin just fetches what YOU tell it to via
Qualifer
There is internal Koin logic that does what you're saying, but not sure why it would be exposed publicly
from
InstanceRegistry.kt
Copy code
@Suppress("UNCHECKED_CAST")
    internal fun <T> getAll(clazz: KClass<*>): List<T> {
        val instances = instances.values.toSet()
        val potentialKeys: List<InstanceFactory<*>> =
                instances.filter { instance -> instance.beanDefinition.hasType(clazz) }
        return potentialKeys.mapNotNull {
            it.get(defaultInstanceContext(null)) as? T
        }
    }
m
am just talking about multibindings. it’s well known feature in Dagger for example and it’s really useful
I don’t want it arbitrarily putting objects in lists lol. just what I tell it to. and it could do that on it’s own, Dagger has annotation for that, and I don’t want to provide list which is error prone. you forget something….. BOOM on runtime
s
ah i see, sorry didn't fully understand what you meant in the original post
quick google search showed this: https://github.com/InsertKoinIO/koin/issues/772
Copy code
single { FooBarJob(get()) } bind Job::class
getKoin().getAll<Job>()
good luck to you 👍
m
thank you very much!