In this case KoinRepositoryLetters depends on Koin...
# koin
f
In this case KoinRepositoryLetters depends on KoinRepoA(), KoinRepoB(), KoinRepoC(), which all take a ServiceA, ServiceB and ServiceC The error I get is that the bean definition for KoinRepoA() is not found
b
see
org.koin.experimental.builder
package - using
org.koin.experimental.builder.scoped
extension
Copy code
import org.koin.experimental.builder.scoped

val scopedFeatureLettersModule = module {
    //with scope
    scope(named("LETTERS_SCOPE")){
        scoped<KoinRepositoryLetters>()
    }
    // definitions inside of scope
    viewModel { FeatureLettersViewModel(get(), get()) }
}
module:
org.koin:koin-core-ext
f
this would change how to specify the dependencies to koin but I think that my conceptual error would still remain even after migrating to extensions
your suggestion is super valid yet doesn't help me understand what I'm doing wrong in my dependency tree 😅
f
thank you I still don't grasp how a complicated/nested tree looks like All the examples I seem to find are straight forward A and B
Whereas in mine I have something like KoinRepositoryLetters(,,) depends on ->KoinRepoA(), KoinRepoB(), KoinRepoC() which each depend on ServiceA,ServiceB,ServiceC FeatureLettersViewModel(,) depends on -> KoinRepositoryLetters(,,) and KoinSingletonUtility KoinSingletonUtility has no dependencies
The reason why I want to scope it is to try and see if I can use this lib for future projects and feature scope it while maintaining as simple of a graph as I can I don't want to have just a Repo class at app context level managing everything all the time so my dependencies are a little bit more complicated than the examples out there
b
You can. On one Gradle project, I have about 12 submodules, each of which is described as a separate Koin module, which can then be integrated as convenient
f
yeah, that's more or less what I want but I'm failing at understanding why my nested dependencies are not found 🤷‍♂️
b
In the example above, you should have done something like this:
Copy code
import org.koin.experimental.builder.scoped
val scopedFeatureLettersModule = module {
    //with scope
    val namedLettersScope = named("LETTERS_SCOPE")
    scope(namedLettersScope){
        scoped<KoinRepositoryLetters>()
    }
    val scopeLetters = koin.createScope(namedLettersScope.value, namedLettersScope)
    // definitions inside of scope
    viewModel { FeatureLettersViewModel(scopeLetters.get(), get()) }
}
👍 1
f
thanks! BTW is there a way to get the koin app reference from a class that is not an Activity? Perhaps a different import or should I handle that reference across the app myself?
f
I see, complicated to have to do
koin.createScope
in the example above as it doesn't play nice with a separated module file that has no reference to getKoin() On the other hand, perhaps it makes more sense that the feature scope is declared when/where used 🤔 ,as in, in an Activity