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

Damiano Giusti

03/28/2023, 9:26 AM
Hello there! Could someone give some hints about using custom scopes in Koin? I’m trying to refactor the dependency management in my Android app by creating a
LoggedUserScope
, so that I can provide fresh instances of certain classes at each login. I identified the classes that are used after the login and the ones that are used before the login. 90% of them are used after the login. I have a couple of questions: 1. does this mean that I need to change all the
single
declarations to be
scoped
in the
LoggedUserScope
? 2. how can I verify that the dependencies resolution is working correctly? I’m using the
checkModules
test method but I think I need to provide the
LoggedUserScope
somehow Thanks to everyone that will help!!
🍿 1
a

arnaud.giuliani

03/31/2023, 12:58 PM
use you need
scoped
definitions instead of
single
, and put it in a
scope
block
if your app is using the same scope at 90% I would suggest to think about dropping your entire configuration once you loggout, instead of having everything in scope
d

Damiano Giusti

03/31/2023, 2:27 PM
thanks @arnaud.giuliani! how can I drop the configuration at logout?
stopKoin
and then restart?
a

arnaud.giuliani

03/31/2023, 2:33 PM
yes, or also
unloadKoinModules
if you have a main module with `included`sub modules
d

Damiano Giusti

03/31/2023, 2:34 PM
yes I do have a main module that groups all the modules for ease of use, also for tests. Thanks I’ll give it a try!
a

arnaud.giuliani

03/31/2023, 3:51 PM
ping me if you need 👍
5 Views