https://kotlinlang.org logo
#dagger
Title
# dagger
c

Colton Idle

03/19/2024, 4:06 PM
I've been out of the dagger/hilt game for a little bit so just want a sanity check. I have a class that is annotated with @Inject, and it seems like I can use it in my android HiltViewModels just fine. That class is not in any @Module though. I now want to make that @Inject a
@Singleton
but, does that mean I have to add it to a module that it @InstallIn(SingletonComponent:class)?
n

Nicholas Doglio

03/19/2024, 4:08 PM
No you do not need to add it to a module with
@InstallIn(SingletonComponent:class)
@Singleton class MyClass @Inject constructor()
is enough to get it on the DI graph as a singleton
c

Colton Idle

03/19/2024, 4:12 PM
thank you 🙏
2 Views