-
-
Notifications
You must be signed in to change notification settings - Fork 719
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
ViewModel scope handling in 3.5.4-RC1 #1821
Comments
I also encountered this problem. For scoped view model:
If I scope the view model to the root scope:
I see that there's this new |
Does not work with |
The use of module {
viewModelOf(::MyScopeViewModel)
scope<MyScopeViewModel> {
scopedOf(::Session)
}
}
class MyScopeViewModel : ScopeViewModel() {
// on onCleared, scope is closed
// injected from current MyScopeViewModel's scope
val session by scope.inject<Session>()
} You need to have a scope with |
Hello, @arnaudgiuliani , Let's say I have a user session scope where I have scoped the current AccountEntry dependency. Scoping multiple user sessions to multiple view models won't work because the view models are part of a single user session. They depend on what it provides. Also, handling dependency injection is not part of the view model's responsibilities and it could also prove difficult to integrate your |
Why was this labeled as a |
I reverted back the capacity to use ViewModel and scopes. |
Let's reopen something for 3.5.4-RC2 if really something goes wrong |
With the changes introduced in this pull request (aiming to fix the previously broken view model scoping issue) passing a
Scope
to theresolveViewModel(...)
function has been deprecated andKoinViewModelFactory
now useskoin.scopeRegistry.rootScope
for every view model. This introduces breaking changes for projects which have multiple activeScope
s (for example application scope / user session scope). With the new changesKoinViewModelFactory
would look for dependencies directly inside the root scope (application scope in my case) and fail to instantiate view models with dependencies scoped as a part of a user session scope.Steps to reproduce the behavior:
Scope
val exampleScope = Koin.getOrCreateScope(ExampleId, ExampleQualifier, ExampleSource)
exampleScope
ExampleViewModel
ExampleDependencieOne
andExampleDependencieTwo
in the root scopeKoin module and version:
koin-core:3.5.4-RC1
The text was updated successfully, but these errors were encountered: