I have a feature where I need to have different Room Databases for different users. I am using Dagger 2 for creating Room Database. My Application Component creates one room database. When user switches to another user I want to create new Room Database for that I would need new Application component to be created. I am able to do that but the old one will still exist. How can I destroy the old Application Component and Create new Application Component.
I am defining Application Component in Application class as shown below:
var daggerComponent: ApplicationComponent? = null
daggerComponent = DaggerApplicationComponent.builder().application(this).build()
ApplicationInjector.init(this) { application ->
daggerComponent?.inject(application)
}
When switching users I am trying to do this:
val appComponent = DaggerApplicationComponent.builder().application(application = application).build()
ApplicationInjector.init(propertyManagerApplication) { application ->
appComponent?.inject(application)
}
How can I destroy the old component completely and then create a new component so that only one component exists at a point of time