Hello, I'm using Koin's "Custom Scopes" and "Scop...
# koin
s
Hello, I'm using Koin's "Custom Scopes" and "Scope linking" to achieve a behavior similar to CompositionLocal in Compose where locally provided definition overrides globally provided definitions. Is there any plan to reopen this issue? https://github.com/InsertKoinIO/koin/issues/1413 if yes, I'll be happy to contribute.
a
You mean cascading scope resolution?
s
Yes, just to be on the same page, the linked GitHub issue in my message has provided the example and the required desired behavior. https://github.com/InsertKoinIO/koin/issues/1413
a
you are trying to create a scope per Composable then?
s
I referred to Compose and Composition Locals to explain the behavior I'm aiming for, but currently, I'm not using Jetpack Compose. I'm trying to create a similar tree-like structure that Composable has with Koin Scopes.
a
You already have
KoinScope
for that, but opening a KoinScope doesn't link explicitly to the previous parent one. It's opening it, through the declaration
something I could look at, if it seems intersting
s
Yes, Koin does provide
Scope
and
Scope::linkTo(vararg scopes: Scope)
API to form this tree-like structure. It works great. The only difference arises when the dependencies are provided at multiple levels. for eg.
Scope C -- (linked to) --> Scope B -- (linked to) --> Scope A
where C is the leaf node, B is the parent node and A is the grandparent node. if a dependency
'Dep'
binding is provided in both scopes 'B' and 'A', and is resolved using scope C like
C.get<Dep>()
then, the instance of 'Dep' is resolved from grandparent 'A' instead of the first parent 'B'. This hinders the ability of lower scopes to override the dependencies that are present at the parent or higher-level Scopes.