You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to introduce a dependency in my ViewModel that is tied to the ViewModel (its life and death should work with the life and death of the ViewModel)
This code (copied from the official koin resource) works
class MyScopeViewModel : ViewModel(), KoinScopeComponent {
override val scope: Scope = createScope(this)
// inject your dependency
val session by scope.inject<Session>()
// clear scope
override fun onCleared() {
super.onCleared()
scope.close()
}
}
However this is not what I want to achieve , I want to inject the Session class as a Constructor argument like this
class MyScopeViewModel(val session:Session) : ViewModel(){
}
The above responds with the exception stating that the Session bean could not be found.
What am i missing here ?
Koin Version - 3.5.0
The text was updated successfully, but these errors were encountered:
yeah @arnaudgiuliani , this appears to be quite necessary to have dependencies injected that are scoped to the ViewModel itself , and not single<> (kinda like what ScopedViewModel does , but yeah would want to do that in a normal androidx.ViewModel)
A use case can be for example a facility to sort a student list in a StudentViewModel called StudentSorter(). The StudentSorter class doesn't need to survive StudentViewModel death.
I want to introduce a dependency in my ViewModel that is tied to the ViewModel (its life and death should work with the life and death of the ViewModel)
This code (copied from the official koin resource) works
However this is not what I want to achieve , I want to inject the Session class as a Constructor argument like this
The above responds with the exception stating that the Session bean could not be found.
What am i missing here ?
Koin Version - 3.5.0
The text was updated successfully, but these errors were encountered: