Is there any common accepted strategy for sharing ...
# compose
p
Is there any common accepted strategy for sharing variables between the entire application in Compose MVVM? for example, a session token that is obtained in a login screen, the username and the data of the logged user, etc... (so it's initially stored in the uistate and the viewmodel of that screen), but then you need it on the entire application for using it in various methods of the rest of screens. I thought that using DataStore whould be acceptable, but after trying it, don't feel ok. So finally I opted for doing a "SessionRespository" class that only is present in memory, during the current session, and you can inject it with Koin and then you can read and write the variables:
Copy code
class DefaultSessionRepository() : SessionRepository {
    override var user: String? = null
    override var sessionToken: String? = null
}
What do you think? do exist a cleaner way?
o
Kinda unrelated to Compose IMO. You have to solve this with View based applications as well. Usually, it's solved through DI (whatever the DI strategy, manual, Dagger, Koin…). There is a Compose specific way to bootstrap injection with Koin though.