I am new to dagger hilt and dependency injection in general. I followed some exemples i could found and i manage to set up my application with hilt and it's woking perfectly. However i am using a serviceComponent in one of my activity to provide some database and from what i could understand provider is very useful because it's allow me to init and provide my data base when needed. My problem is that i don't fully get how it's working right now. And i would like to be able to change my database but the provider seem to be called only one time so i can do that. Here is my module :
@Module
@InstallIn(ServiceComponent::class)
object ServiceModule {
@ServiceScoped
@Provides
fun provideMusicDatabase() = MusicDatabase(listOfSong)
}
This work the first time to provide my activity the MusicDatabase but when i try to change my listofsong, i don't know how i can notify my service that something has changed. So i would like to know if there is a way to reinit/delete/clear a ServiceComponent so i can update my database. Or maybe i am just using the wrong hilt tool because i am not really familiar with it ?
Also i would like to notifie that even when i finish my activity and it get destroyed, my ServiceComponent is not reinit when i reopen the activity. I am guessing that it's the normal behaviour but i'am new to hilt so i don't really know. So maybe i need to change annotation so it reset when i i restart the activity. I also tried to change @ServiceScoped to @ActivityScoped for the MusicDatabase provider but it did not work.
So maybe i am just missing the whole point of hilt or i didn't get how to use it. But it would be very nice if i could get some help on this.