-
Notifications
You must be signed in to change notification settings - Fork 95
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
Can I integrate koin in compose multiplatform with koin ViewModel?? #262
Comments
@shohrab-swl Yes, you can. And in your composable use your above code snippet and instead of declaring I have created an example here - https://github.com/NikhilBhutani/ComposeMultiplatformNewsAppDemo/blob/main/shared/src/commonMain/kotlin/com/niko/kmm/newsappdemocomposemultiplatform/di/PresentationModule.kt |
Hi @Alex009 , Can we please mark this as resolved ? |
That code doesn't work when I create a new ViewModel. |
@shohrab-swl Can you please share your repo so that I can check whats not working for you? Or maybe you can clone my repo above and add api key to inspect how it's working. ? Let me know, glad to help out in any way. |
NewsAppDemoComposeMultiplatform.zip fun presentationModule() = module { object ViewModelsFac : KoinComponent { I just changed a few lines. and i get this error java.lang.ClassCastException: com.niko.kmm.newsappdemocomposemultiplatform.presentation.details.NewsDetailsViewModel cannot be cast to com.niko.kmm.newsappdemocomposemultiplatform.presentation.NewsHomeViewModel |
Thanks for sharing this @shohrab-swl , Can you please also add an issue in the original repo, I'll fix this. |
@shohrab-swl You can do this.
and access it with getViewModel in your composable. |
It's hard to understand the concept, but I made it work based on this conversation. I suggest you to add this case to the instructions |
Is it possible to koinInject??
The text was updated successfully, but these errors were encountered: