-1

We are developing new Android app, only using Kotlin language.

We want to use Dependency Injection framework. Dagger 2 is Java based framework. As of my knowledge, There is no Kotlin based DI framework from Google.

  1. Is it advisable to use Dagger 2 with Kotlin?
  2. When can we expect Kotlin based DI framework from Google? If so, is it backward compatible with Dagger 2 to adopt quickly?

4 Answers4

6
  1. Yes, you could use Dagger 2 with Kotlin. Kotlin is working over JVM and totally interoperable with Java.

  2. I haven't heard about such kind of plans. Just use Dagger 2 on your Kotlin project and you'll see that it works great.

3
  1. You can use dagger 2 with Kotlin, and there shouldn't be any issues.
  2. I am not sure if Google is going to develop one, however if dagger compatibility is not an issue then there is an existing DI framework Koin written in Kotlin.
jaga
  • 753
  • 11
  • 18
1

Dagger 2 should work with Kotlin. We know there are a few rough edges for Kotlin users, and we're looking to smooth them over.

netdpb
  • 401
  • 3
  • 4
0

Koin and kodein are not DI containers, but are Service Locators. If you consider that you need only DI container and Service Locator is not good for you, then probably the Koin/kodein is not a good choice. The choice is yours. The difference can be seen here What's the difference between the Dependency Injection and Service Locator patterns?.

Jake Warton conversation also throws light on the same stating

DI pattern > service lookup pattern. Code generates the boilerplate for manual DI. Compile-time validated for completeness. Fast at runtime.

https://twitter.com/JakeWharton/status/908419644742098944?ref_src=twsrc%5Etfw%7Ctwcamp%5Etweetembed%7Ctwterm%5E908419644742098944&ref_url=https%3A%2F%2Fmedium.com%2Fmedia%2Ffc6b4ad54c27f761700f5726ed92cfd1%3FpostId%3Df5bc5eaa308e

Raghav Sharma
  • 780
  • 10
  • 18