Bug
According to https://insert-koin.io/docs/1.0/documentation/reference/index.html#_koin_dsl, Section 2.11, I should be able to request dependency from a specific module namespace but I'm not.
Expected behavior
Should work as shown in the documentation
Koin project used and used version (please complete the following information):
koin-core version 1.0.1
Hello,
doc is a bit outdated. the module property doesn't exist anymore, but you can use name instead.
Thanks for the update.
Can you please introduce a way where I can just give the module identifier(like a name/path) to inject and it automatically resolves based on the visibility hierarchy(current to root) instead of adding data type as a suffix everytime I need to resolve a variable. All of my injected variables are now looking like this:
val modulePath = "authModule"
val someClass: ClassType by inject(name = "${modulePath}.ClassType")
Adding a few variables quickly makes the class too verbose and a lot of redundant repetitions for the modulePath as well. My bean definitions are looking like this:
val module = module(path = modulePath) {
single
}
Defining the datatype for "single" isn't being helpful at all. I've got to add the type in inject anyways.
It'd be also great if I can have an option to define the default modulePath for all the variables in a given class. That way, I'll be forced to explicitly mention the names for variables that differ from the default path.
Got similar problem, I have multiplies repositories defined in modules like this
module("CountRepository") {
single
single
}
module("UserRepository") {
single
single
}
When I try to inject
private val localUserRepository: Repository<User> by inject(LOCAL)
I got error.
Caused by: org.koin.error.DependencyResolutionException: Multiple definitions found for type 'interface ...repository.base.Repository (Kotlin reflection is not available)' - Koin can't choose between :
Single [name='local',class='...Repository', path:'CountRepository']
Single [name='local',class='...Repository', path:'UserRepository']
A way to explicitly specify a module would be great
A definition name should be unique. Why reuse a name for another definition?
Giving a name to each dependency is so tedious and pointless for me. When we used Dagger we defined such names with @Named annotation and we could resolve correct dependency using these const string values
A definition name should be unique. Why reuse a name for another definition?
I agree. Names should be unique. But the lack of option to specify a module for injection is the major problem. Composing injection for every declaration like "${modulePath}.ClassType" isn't looking elegant. In fact it gets super verbose and highly unreadable in larger classes.
We're using injection by name as a shortcut to circumvent this verboseness and that brings "find a unique name for every definition" problem. Multiple definitions might exist with slight variations and coming up with a unique name for every single one of them is not practical, and can get very messy if we do.
Yeah, that's the problem about namespaces.
In 1.1.x I consider to abandon namespaces and deal with only name & types to bind.
Check if needed in 2.0.0