26

What dependency injection for Android with Kotlin do you prefer? I have started using Kodein but i don't want to lose my time if Koin it's better.

I have read this presentation https://www.kotlindevelopment.com/koin-vs-kodein/ by Makery Kotlin Development it's really nice.

From that presentation these are the differences:

Kodein

  • Robust
  • Tons of feature
  • Great documentation
  • More complicated API

Koin

  • Smaller
  • Less feature
  • Natural API

Github stars Kodein 1164 vs 1350 Koin


Thanks !!

SergioCT
  • 401
  • 1
  • 7
  • 12
  • 16
    This is a very opinionated, sweeping statement without any substance to it. While it's important to understand the shortcomings of Koin (which is essentially a service locator rather than a proper DI framework), it's a very viable alternative for projects of moderate size. Dagger 2 is more complex and requires more boilerplate, not to mention it adds up to the build time. It may be an overkill for a lot of Android projects, where the use of DI typically boils down to nothing else but substituting dependencies with mocks for testing purposes. (I can't comment on Kodein as I haven't used it) – Konrad Morawski Sep 30 '18 at 17:48

1 Answers1

17

As my project is small I prefer Koin, because is lightweight library. It has a good API for scopes and wrapper for VM from Android Architecture Components. But you should know that Koin looks like Service Locator.

Amin Memariani
  • 830
  • 3
  • 17
  • 39
Aleksandr Melnikov
  • 310
  • 1
  • 3
  • 10
  • 1
    Is Service Locator better than Dependency Injection? – IgorGanapolsky Oct 15 '18 at 14:46
  • 3
    @IgorGanapolsky you should prefer patterns or tools based on your situation in the project. I think if you sure that your project is small and you don't need complex solution for IoC, then you can choose Koin or you can manual insert of dependencies. You can see a better explanation here https://www.reddit.com/r/androiddev/comments/8ch4cg/dagger2_vs_koin_for_dependency_injection/dxf1bmw – Aleksandr Melnikov Oct 16 '18 at 08:50
  • 4
    Thanks for that link. According to the discussion there, there is no silver bullet, and nobody knows how to pick the best pattern for the job at hand :) – IgorGanapolsky Oct 16 '18 at 13:19
  • @IgorGanapolsky Not at all. You absolutely right, no silver bullet. :) – Aleksandr Melnikov Oct 16 '18 at 15:01