Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restarting single instances in Koin #676

Closed
luispereira opened this issue Dec 18, 2019 · 3 comments
Closed

Restarting single instances in Koin #676

luispereira opened this issue Dec 18, 2019 · 3 comments
Labels
question Usage question

Comments

@luispereira
Copy link

I'm trying to implement a session mechanism, where the user can logout and login at any moment with other account. In order to avoid having inconsistent information, I wanted to restart some instances within a module that I like this:

 val sessionRepositories = module {
     single { UserSessionRepository(androidApplication(), get(), get()) } bind AbstractSessionRepository::class
}

To this I tried to do:

unloadKoinModules(sessionRepositories)
loadKoinModules(sessionRepositories)

And for what I know, this will drop the previous UserSessionRepository instance and will create a new one, creating a leak with the previous UserSessionRepository. Therefore, I tried to do:

MyApplication.getInstance().stopKoinInstance()  //calls GlobalContext.stop()
MyApplication.getInstance().startKoinInstance() //restarts all instances, just to see if there was something with load and unload

And this keeps leaking, is there a way, where I can really restart my instances

@HarryMMR
Copy link

HarryMMR commented Dec 21, 2019

I did a session management like what you want using a custom scope. It works pretty well. After user logins, you can start scope, and when user logouts, you can close the scope.
https://doc.insert-koin.io/#/koin-core/scopes?id=using-a-scope

@arnaudgiuliani arnaudgiuliani added the question Usage question label Jan 6, 2020
@MoustafaElsaghier
Copy link

MoustafaElsaghier commented Oct 2, 2022

any direct update from koin for doing the restart-specific view model
?

@sureshmaidaragi1919
Copy link

@luispereira any workaround for your usecase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usage question
Projects
None yet
Development

No branches or pull requests

5 participants