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
migrating koin version from 2.1.6 to 3.1.5 broke our generic ViewModel delegation structure #1323
Comments
The only workaround (as of version 3.1.6) is to use |
The ViewModel API is complex to maintain. I'm more thinking to have default APIs and have a kindof DSL to help specify the way you want to use it. We have so much combination of arguments, that it become really hard |
Hi, I have this same issue. How do I use the java-compat module. So I just import this dependencyand it should work as before? |
Maybe I misunderstood the question, but I solved a similar problem in the following way |
@Nemo996 Hi, I've tried your solution, but with custom scope and it's not working. Thank you |
still need some clearer API 👍 Next patch will help |
Generic access to ViewModel API is available in |
Describe the bug
We've been using generic type ViewModel in our project and initialising it like below in a BaseFragment
protected abstract val vmClazz: KClass<VM> val viewModel: VM by lazy { getViewModel(vmClazz) { parametersOf(arguments) } }
Note: getViewModel method is from the package org.koin.androidx.viewmodel.ext.android
But, after migrating the koin version to the latest (3.1.5) it doesn't compile anymore and showing the below error:
Cannot use 'VM' as reified type parameter. Use a class instead.
Property delegate must have a 'getValue(BaseFragment<X, X, VM, X>, KProperty<*>)' method. None of the following functions is suitable: public inline operator fun <T> Lazy<ViewModel>.getValue(thisRef: Any?, property: KProperty<*>): ViewModel defined in kotlin
Also, in a singleton definition when we're trying to use the getProperty() from the package org.koin.core.scope
file, there is another error in a module file, which is saying,
Not enough information to infer type variable T
As I understood, we can't use the generic type ViewModel using the KClass features as it can't infer its type as a generic.
In conclusion, we cannot upgrade our koin version because of the feature misses in a new version.
Expected behavior
There are neither a single update info nor the change logs in a documentations. I cannot find any alternatives to accomplish my requirements.
Please, provide these missing features from the previous versions or provide an alternative way to achieve above requirements as we don't want to define ViewModel types explicitly.
Koin project used and used version (please complete the following information):
We are using
implementation "io.insert-koin:koin-android:2.1.6" implementation "io.insert-koin:koin-androidx-viewmodel:2.1.6"
The text was updated successfully, but these errors were encountered: