Easy Dependency Injection With Koin 3.2 And Koin Annotations

Dependency Injection for Android Apps has never been simpler

Yanneck Reiß
Tech Takeaways

--

Photo by Alexandre P. Junior on Pexels

The Koin dependency injection (DI) framework has already a reduced complexity in comparison to other options like Dagger.

However, using the latest Koin version 3.2, we now can make use of a few new functionalities that reduce the complexity of integrating DI into our Android app even more.

One of the new features are Koin Annotations plugin. It uses the KSP (Kotlin Symbol Processing API) to provide a compiler plugin that allows us to declare our injectable classes via annotations. That means that, for simple cases, while we still have the capability to do so, we no longer are enforced to declare additional modules and just need to add a simple annotation above the classes we want to inject.

While Koin Annotations are at the time of writing still in beta, in this article, we will take an early look at how we can declare dependencies with Koin using the usual approach with the new functionalities of Koin 3.2 and also how we can migrate to dependency declarations using Koin Annotations.

1. Declaring Koin Modules (the usual way)

--

--

Yanneck Reiß
Tech Takeaways

Follow me on my journey as a professional mobile and fullstack developer