Hi guys. I have a question regarding reloading of ...
# koin
p
Hi guys. I have a question regarding reloading of modules. In my app I have a base module where the application class is located which starts koin. Than I have a couple of (feature) modules depending on the base module but do not know anything about each other. Now I have a library with where the users login is handled (in a singleton class). I need the same instance in both feature modules but when I try to load the same module twice, koin is telling me, that the definitions already exists and the app crashes. So the question is, how can I (re)load this "account" module without crashing the app? (To declare the modules in the base module is no option for me)
@arnaud.giuliani Do you have an idea regarding my issue?
a
You should use scopes, to declare components that you have to drop later
p
so when I have a module with scoped definitions (not tied to any scope) and load this module twice, the app would not crash with an exception (“Already existing definition or try to override an existing one”)?
a
with scope, you replace your need of reloading modules by creating and closing scope instances
each scope instance allow to resolve your component, and keep it until you close this scope instance
p
Nevertheless I somewhere have to load the module with scopes inside of it at least once
With my current understanding ^^ Or I completely misunderstand Koin