[英]Kotlin with Dagger 2
We are developing new Android app, only using Kotlin language.我们正在开发新的 Android 应用程序,仅使用 Kotlin 语言。
We want to use Dependency Injection framework.我们想使用依赖注入框架。 Dagger 2 is Java based framework. Dagger 2 是基于 Java 的框架。 As of my knowledge, There is no Kotlin based DI framework from Google.据我所知,谷歌没有基于 Kotlin 的 DI 框架。
Yes, you could use Dagger 2 with Kotlin.是的,你可以在 Kotlin 中使用 Dagger 2。 Kotlin is working over JVM and totally interoperable with Java. Kotlin 在 JVM 上工作,并且可以与 Java 完全互操作。
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.只需在您的 Kotlin 项目中使用 Dagger 2,您就会发现它运行良好。
Dagger 2 should work with Kotlin. Dagger 2 应该与 Kotlin 一起使用。 We know there are a few rough edges for Kotlin users, and we're looking to smooth them over.我们知道 Kotlin 用户有一些粗糙的地方,我们正在努力解决这些问题。
Koin and kodein are not DI containers, but are Service Locators. Koin 和 kodein 不是 DI 容器,而是服务定位器。 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.如果您认为您只需要 DI 容器并且 Service Locator 不适合您,那么 Koin/kodein 可能不是一个好的选择。 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. DI 模式 > 服务查找模式。 Code generates the boilerplate for manual DI.代码为手动 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 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.