Заготовка
This commit is contained in:
50
client-mobile/chats/di/LocalDatabaseModule.kt
Normal file
50
client-mobile/chats/di/LocalDatabaseModule.kt
Normal file
@@ -0,0 +1,50 @@
|
||||
package chats.di
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Room
|
||||
import androidx.work.WorkManager
|
||||
import chats.data.local.dao.ChatDao
|
||||
import chats.data.local.dao.MessageDao
|
||||
import chats.data.local.dao.UserProfileDao
|
||||
import chats.data.local.database.AppDatabase
|
||||
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
|
||||
|
||||
/**
|
||||
* Hilt модуль для предоставления зависимостей локальной базы данных и WorkManager
|
||||
*/
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object LocalDatabaseModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideAppDatabase(@ApplicationContext context: Context): AppDatabase {
|
||||
return Room.databaseBuilder(
|
||||
context,
|
||||
AppDatabase::class.java,
|
||||
AppDatabase.DATABASE_NAME
|
||||
)
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun provideMessageDao(database: AppDatabase): MessageDao = database.messageDao()
|
||||
|
||||
@Provides
|
||||
fun provideChatDao(database: AppDatabase): ChatDao = database.chatDao()
|
||||
|
||||
@Provides
|
||||
fun provideUserProfileDao(database: AppDatabase): UserProfileDao = database.userProfileDao()
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideWorkManager(@ApplicationContext context: Context): WorkManager {
|
||||
return WorkManager.getInstance(context)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user