how do I do a constructor injection with Koin?
# koin
b
how do I do a constructor injection with Koin?
a
In a nutshell you need to : 1. Pass an interface or class in the constructor 2. Inside the composite root of your application, create a koin module and declare a binding to let Koin know that this implementation should be used when asking for this interface. 3. Add your module inside
startKoin
4. Inside your composite root or inside your view, call
get<YourInterface>()
or
inject<YourInterface>
on the koin application to retrieve the dependency. Note : Inside your object, you should not use the DI application directly to not tie your class to a DI framework. This is why the dependencies are passed in the constructor, the object never knows where it came from. You can also check the official doc for better guidance https://insert-koin.io/