Прочтение
This commit is contained in:
32
client-mobile/core/di/DatabaseModule.kt
Normal file
32
client-mobile/core/di/DatabaseModule.kt
Normal file
@@ -0,0 +1,32 @@
|
||||
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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user