https://kotlinlang.org logo
#koin
Title
# koin
s

sarthak sehgal

12/05/2023, 11:18 AM
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

arnaud.giuliani

12/05/2023, 4:28 PM
You mean cascading scope resolution?
s

sarthak sehgal

12/05/2023, 6:35 PM
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

arnaud.giuliani

12/06/2023, 8:42 AM
you are trying to create a scope per Composable then?
s

sarthak sehgal

12/06/2023, 9:02 AM
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

arnaud.giuliani

12/06/2023, 9:15 AM
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

sarthak sehgal

12/06/2023, 9:55 AM
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.