36 lines
916 B
Kotlin
36 lines
916 B
Kotlin
package core.di
|
|
|
|
import android.content.Context
|
|
import androidx.room.Room
|
|
import core.database.data.ChatDatabase
|
|
import core.database.data.MessageDao
|
|
import core.database.data.MIGRATION_1_2
|
|
import dagger.Module
|
|
import dagger.Provides
|
|
import dagger.hilt.InstallIn
|
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
|
import dagger.hilt.components.SingletonComponent
|
|
import javax.inject.Singleton
|
|
|
|
@Module
|
|
@InstallIn(SingletonComponent::class)
|
|
object DatabaseModule {
|
|
|
|
@Provides
|
|
@Singleton
|
|
fun provideDatabase(@ApplicationContext context: Context): ChatDatabase {
|
|
return Room.databaseBuilder(
|
|
context,
|
|
ChatDatabase::class.java,
|
|
ChatDatabase.DATABASE_NAME
|
|
)
|
|
.addMigrations(MIGRATION_1_2)
|
|
.build()
|
|
}
|
|
|
|
@Provides
|
|
fun provideMessageDao(database: ChatDatabase): MessageDao {
|
|
return database.messageDao()
|
|
}
|
|
}
|