33 lines
843 B
Kotlin
33 lines
843 B
Kotlin
package core.di
|
|
|
|
import android.content.Context
|
|
import androidx.room.Room
|
|
import core.database.data.ChatDatabase
|
|
import core.database.data.MessageDao
|
|
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,
|
|
"chat_database"
|
|
).fallbackToDestructiveMigration().build()
|
|
}
|
|
|
|
@Provides
|
|
fun provideMessageDao(database: ChatDatabase): MessageDao {
|
|
return database.messageDao()
|
|
}
|
|
}
|