Koin Framework- Provide ViewModel Dependency (Part-3) - Most Underrated Framework

This will be the third part on Koin Framework, where we will see how we provide the dependency of ViewModel through Koin🥰

Other Articles on Koin Framework

First add this dependency in build.gradle(Module) file

In the above code we have one interface and a class is providing the implementation . Now we want to use this interface(Demo) in ViewModel. So what we will do we will create a ViewModel and pass as a parameter.😋😋

Now it’s time to create the dependency of “MainViewModel”. Remember that MainViewModel class taking demo interface as a parameter so first we will provide the dependency of that!

This is how we provide the dependency of ViewModel ! Cool👌💖

Now add this Module in BaseApp

if you want to use this ViewModel , simply create the instance though “viewModels()” Ktx library.

private val mainViewModel:MainViewModel by viewModel()

That is all for today my friends. Hope you enjoyed this article and learnt something new. Keep learning happy coding💖



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jayant Kumar

Jayant Kumar


Hey my name is jayant and i am a youtuber and software Engineer at @Antino