Why we need yet another dependency injection framework for Kotlin & Android

Sven Jacobs
Oct 29, 2018 · 3 min read
“assorted electric cables” by John Carlisle on Unsplash

At the beginning of this year my colleague and I started a new Android application project. Being a greenfield project we had no technical constraints. Therefore during the planning phase we sat down and made a wish list of which technologies we want to use. Obviously 100% Kotlin was a no-brainer! Eventually we came to the point of dependency injection. We have lots of experience with Dagger 2 but felt that we should give one of the new Kotlin-specific frameworks a try, utilising the full potential of Kotlin. Also we decided to use Conductor for the UI so we had no benefits of using Dagger since we couldn’t use Dagger’s Android extensions which remove a lot of the boiler plate code. We looked at Koin and Kodein, both popular libraries in the Kotlin community. However these frameworks didn’t suit us and either had too many features that we don’t need or — according to our opinion — questionable design decisions which might introduce complex problems within the Android environment. For instance Koin works with a global singleton object. Modules are added to and removed from the object during runtime. We felt that this concept might introduce memory leaks, especially when injecting instances of Android framework classes and not properly releasing the modules (in the right order). Later Koin introduced scopes but the original problem remains. We thought that there’s already a perfect tool for handling the scope of objects, which has been with the JVM from the very beginning: the garbage collector. Why should I have to explicitly bind and release scopes or modules when the garbage collector can do this job?

That’s why we decided to write our own dependency injection framework for Kotlin with Android in mind. After all a dependency injection framework is just a glorified hash map, right? 😉

After a few weeks of development and fine tuning and months of internal testing we’re happy to announce Katana, our vision of a lightweight and minimalistic dependency injection framework 🎉

Slices of Katana

For more technical explanations, examples and an Android demo application please visit our GitHub page.

We believe that Katana fills a niche in the realm of dependency injection frameworks suitable for Android, broadening the choice for developers. If you are looking for a lean framework which is as good as handwritten dependency injection maybe Katana might be right for you.

Please have a look at Katana, try it out, spread the word, report bugs and feature requests and let us know when you’re using Katana in your application. Many thanks! 🙂

Further reading

Sven Jacobs

Written by

Software engineer developing mobile applications in modern languages.