DEV Community

Discussion on: Experimenting with Dagger Hilt

Collapse
 
gastsail profile image
Gastón Saillén • Edited

Great article Pushkar, I will note that in the DBModule the Room instance should be generated with @Singleton on top of @Provides since we just need one instance of the Room DB to run in the whole project since @InstallIn(ApplicationComponent::class) will not generate just one instance of it, instead it will scope the creation of that instance to the ApplicationComponent and will generate new ones each time its called in the repository.

The solution to just have 1 instance of the DB running in the lifetime of the ApplicationComponent is to annotate @Singleton above @Provides in the module

Collapse
 
anandpushkar088 profile image
Pushkar Anand

Thanks for the feedback. I will update the article with usage of @Singleton.