Koin Framework- Provide Interface Dependency (Part-2)- Most Underrated Framework🤔

Jayant Kumar🇮🇳
2 min readNov 7, 2021
Photo by Sergei A on Unsplash

This is gonna be the “second part” on Koin Framework, where we will see how to provide the dependency of interface through Koin.😍

Other parts of Koin Framework Link

Case- 1

You can see in the above code we have an interface “Demo” and “DemoImpl” class is implementing Demo interface (or proving the body for Demo) and in the Main class we are using Demo interface.Suppose you want to use Main class somewhere, so whenever we create the object of Main , we also have to pass the dependency (object) of Demo Interface😁.

we all know that here we are using DI , so what we can do we can provide the dependency of Demo , DemoImpl and Main class in Module file.Alright !😉

you can see in the above code there are three ways to provide the dependency of Demo interface , you can prefer anyone but the recommended one with “bind” keyword and at the last we provide the dependency of Main class 💖

Case- 2

Let’s talk about Case 2 , suppose we have two interface (UserOne,UserTwo) and “UserImpl” class implementing both interfaces , after that MainUser class using both interfaces . Now see , here is the question how we can provide the dependency of both interface because these interfaces are implemented by same class (Main class) for that let’s create another Module file.😀

In the above code you can see if a class implementing more than one interface then we need to use “binds” keyword which takes Array of parameters.👌

Now its time to add these Module files in Base class

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

--

--

Jayant Kumar🇮🇳

Hello , My name is Jayant, I am a tech youtuber and software Engineer from India 🇮🇳