@Singleton vs @InstallIn(SingletonComponent::class)

Viewed 1969

What's the difference between these two? I think they both annotate a singleton object/instance, but somehow @Singleton can be used to annotate methods, instead of classes. I'm really confused about both of them.

2 Answers

ApplicationComponent being renamed to SingletonComponent, to allow usage of Hilt in non-Android Gradle modules link

but @Singleton is a software design pattern link

@SingletonComponent specifies that it can be used in the entire application.

@Singleton is a software design pattern causes the object to be initialized once.

Related