- Lucas' Newsletter
- Posts
- Daily Dispatch #5 - Dependency Injection
Daily Dispatch #5 - Dependency Injection
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/d3492ecb-43a9-4de2-812e-e4a2311b39b7/pexels-photo-239548.jpeg?t=1722263372)
Classes shouldn’t have to fetch their dependencies, you should get a third party module to link implementations with it’s respective interfaces. That way you can change easily the implementations if need be.
Two libraries used for dependency injection are Koin(7.3k stars on GitHub as the time of this post) and Kodein-DI(2.7k stars on GitHub as the time of this post). The main difference that I see is that Kodein-DI works for multi platform apps on Kotlin, however both share many similarities and if your code is neat, you can replace one for the other.
With Koin here’s how it works.
Declaring component’s definitions
Injecting Constructors
Start koin
Injecting
Now for Kodein-DI , I’m still trying to make it work.