Fav123
12/06/2019, 3:25 PMBorzdeG
12/06/2019, 3:29 PMorg.koin.experimental.builder
package - using org.koin.experimental.builder.scoped
extensionBorzdeG
12/06/2019, 3:29 PMimport org.koin.experimental.builder.scoped
val scopedFeatureLettersModule = module {
//with scope
scope(named("LETTERS_SCOPE")){
scoped<KoinRepositoryLetters>()
}
// definitions inside of scope
viewModel { FeatureLettersViewModel(get(), get()) }
}
BorzdeG
12/06/2019, 3:30 PMorg.koin:koin-core-ext
Fav123
12/06/2019, 3:33 PMFav123
12/06/2019, 3:35 PMBorzdeG
12/06/2019, 3:39 PMget()
without specifying scope.
Look at using scope in tests::
https://github.com/InsertKoinIO/koin/blob/55b693496fce1688617af6731407e2e3bab4a43c/koin-projects/koin-core-ext/src/test/kotlin/org/koin/experimental/builder/ScopeDelcarationTest.ktFav123
12/06/2019, 3:44 PMFav123
12/06/2019, 3:44 PMFav123
12/06/2019, 3:47 PMBorzdeG
12/06/2019, 3:51 PMFav123
12/06/2019, 3:54 PMBorzdeG
12/06/2019, 3:58 PMimport 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()) }
}
Fav123
12/06/2019, 4:07 PMBorzdeG
12/06/2019, 4:11 PMFav123
12/06/2019, 4:25 PMkoin.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