I'm concerning how to get ViewModel from Koin with SavedStateHandle.
Here is my DI class:
ViewModelModule.kt
viewModel { ProfileViewModel(userApi = get()) }
Now, I want to try using SavedState module for viewModule that is announced from Google I/O 2019.
Link: https://developer.android.com/topic/libraries/architecture/viewmodel-savedstate
So I declared in my ViewModel as below:
class ProfileViewModel(
private val userApi: UserApi,
private val stateHandle: SavedStateHandle
) : ViewModel() {
Base on Koin concept, I just need define viewModel in ProfileActivity.kt class:
private val viewModel: ProfileViewModel by inject()
But, what should I do with my DI class ViewModelModule.kt to get SavedStateHandle ?
I'm pretty sure that this isn't possible at the moment.
@IVIanuu
Thank for the reply.
Basically I think so
On dagger that's is solved using @AssistedInject, can we expect something similar coming to Koin?
have to check how to use this SavedStateVMFactory with constructor injection
Any updates on this?
This feature is open to contribution if you want to propose something 馃憤
I think we would need to add DSL which passes a savedStateParameter to the bean definition. I could look at it..
viewModelWithState { (savedState: SavedStateHandle, someArgument : String) -> MyViewModel(savedState, someArgument, get(), get()) }
I added a PR for this #496 would appreciate feedback. I know it forces the lifecycle dependencies to update, maybe we can discuss it.
@arnaudgiuliani I think this will be essential functionality. is there a bleeding edge branch you use to point to the latest versions of androidx? If so that would be a better target. I would also love to here your thoughts on my implementation. #496
ok, will check that
closing this, to go on the PR directly