不推荐使用 ApplicationComponent 吗?

Kos*_*nos 33 android dagger dagger-hilt

我刚开始在 Android 上使用 Dagger Hilt 进行依赖注入,我在 Android Studio 上收到一条警告说'ApplicationComponent' is deprecated. Deprecated in Java.

我在谷歌搜索时没有找到与此警告相关的任何内容,它实际上已被弃用还是使用安全?

我还在 Dagger 的网站上注意到他们没有在“迁移到刀柄”指南中的任何地方提及它,他们使用的@InstallIn(SingletonComponent::class)似乎有效,但我不知道为什么。

Sae*_*tfi 82

ApplicationComponent重命名为SingletonComponent,以允许在非 Android Gradle 模块中使用 Hilt链接


小智 7

不推荐使用 ApplicationComponent 吗?

是的,它已被弃用。

相反ApplicationComponent,您可以使用SingletonComponent. 这是用于单例绑定的 Hilt 组件