After upgrading dagger hilt(version: 2.31-alpha
) ApplicationComponent.class
can not find.
What is the alternative for a Component
like RoomDatabase?
@Module
@InstallIn(ApplicationComponent::class)
class RoomModule() {
private val DATABASE_NAME = "salat_time"
@Singleton
@Provides
fun provideRoomDatabase(@ApplicationContext appContext: Context) = Room.databaseBuilder(
appContext,
AppDatabase::class.java,
DATABASE_NAME
).createFromAsset("db/$DATABASE_NAME.sqlite").build()
@Singleton
@Provides
fun provideLocalSalatRepository(database: AppDatabase) = LocalSalatRepository(database)
@Singleton
@Provides
fun provideDistrictRepository(database: AppDatabase) = DistrictRepository(database)
}
ApplicationComponent
is Deprecated in Dagger Version 2.30 ApplicationComponent
removed in Dagger Version 2.31
Alternatively SingletonComponent
should be used instead of ApplicationComponent
@Module
@InstallIn(SingletonComponent::class)
class RoomModule() {
. . .
}
ApplicationComponent is renamed to SingletonComponent
Just import:
import dagger.hilt.components.SingletonComponent
and annotate your module as:
@Module
@InstallIn(SingletonComponent::class)
Because ApplicationComponent is removed in the newer version of daggerHilt and I'm using these dependencies for dagger hilt within app level gradle file:
//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.31-alpha"
kapt "com.google.dagger:hilt-android-compiler:2.28-alpha"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With