vitaliy
10/22/2020, 2:10 PMSCOPE_USER
. This scope is created when user logs in and I close it on logout. There is a custom by injectUser()
function to inject things from this scope for convenience.
Question: is it possible to link SCOPE_USER
to root when it is created and close it when user logs out? Or should I rather create another SCOPE_GENERAL
for all the stuff, that is currently in root and then link SCOPE_USER
to it? This would require to inject from a scope -> custom by injectGeneric()
function. Ideally linking stuff to root scope would be ideal, but I do no see a way to do it. Or should I rather keep things as they are?
Many thanks for any ideas in advance!arnaud.giuliani
10/22/2020, 4:33 PMarnaud.giuliani
10/22/2020, 4:34 PMarnaud.giuliani
10/22/2020, 4:36 PMinjectUser()
with something like:
fun injectUser() = getKoin().getOrCreateScope(SCOPE_USER).get<User>()
vitaliy
10/22/2020, 4:52 PMby inject()
and by viewModel()
methods. I have mixed feelings about this approach, but part of me feels it would be simpler this way. It kind of reverses the notion of scopes falling back to root and makes the root one “be aware” (after linking) about scoped things though.
some context: DI graph is not crazy large, so there is no performance implications, at least not currently. Scope is more to keep all the session-related moments in one bucket and wipe them altogether when user logs out to avoid leaking anything to the next userarnaud.giuliani
10/23/2020, 10:31 AMscope.get()
, scope.inject()
or scope.getViewModel()
. The thing is to retrieve it where you need itvitaliy
10/26/2020, 1:03 PM