android - `@Singleton` 与 `@InstallIn(SingletonComponent::class)`

标签 android singleton dagger-hilt

这两者有什么区别?我认为他们都注释了一个单例对象/实例,但不知何故@Singleton可用于注释方法,而不是类。我真的对他们两个感到困惑。

最佳答案

ApplicationComponent更名为 SingletonComponent , 以允许在非 Android Gradle 模块中使用 Hilt link
但是 @Singleton是一种软件设计模式link

关于android - `@Singleton` 与 `@InstallIn(SingletonComponent::class)`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65010587/

相关文章:

android - 在父应用程序和子应用程序上使用@HiltAndroidApp

android - Kotlin 主要和次要构造函数问题

c# - Azure 函数针对同一服务总线队列消息多次运行

java - 如何从 Android 中的 Parse Server 获取字符串

c++ - 使用单例初始化程序

iphone - 访问单例中的可变值?

kotlin - 为什么要为ApplicationContext对象添加注释@ApplicationContext?

Android Dagger Hilt : Do we need scope annotations for ViewModels?

java - 如何获取Android设备当前的媒体类型?

java - 无法将数据从 firebase 添加到字符串数组