45 lines
1.2 KiB
Kotlin
45 lines
1.2 KiB
Kotlin
package com.postcard.di
|
|
|
|
import android.content.Context
|
|
import androidx.room.Room
|
|
import com.postcard.data.local.ConversationDao
|
|
import com.postcard.data.local.MessageDao
|
|
import com.postcard.data.local.PostcardDatabase
|
|
import com.postcard.data.local.UserDao
|
|
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 providePostcardDatabase(@ApplicationContext context: Context): PostcardDatabase {
|
|
return Room.databaseBuilder(
|
|
context,
|
|
PostcardDatabase::class.java,
|
|
"postcard_db"
|
|
).fallbackToDestructiveMigration().build()
|
|
}
|
|
|
|
@Provides
|
|
fun provideUserDao(database: PostcardDatabase): UserDao {
|
|
return database.userDao()
|
|
}
|
|
|
|
@Provides
|
|
fun provideConversationDao(database: PostcardDatabase): ConversationDao {
|
|
return database.conversationDao()
|
|
}
|
|
|
|
@Provides
|
|
fun provideMessageDao(database: PostcardDatabase): MessageDao {
|
|
return database.messageDao()
|
|
}
|
|
}
|