Создана база данных
This commit is contained in:
@@ -7,13 +7,16 @@ import dagger.hilt.components.SingletonComponent
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import javax.inject.Qualifier
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Qualifier
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
@Singleton
|
||||
annotation class MainDispatcher
|
||||
|
||||
@Qualifier
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
@Singleton
|
||||
annotation class IoDispatcher
|
||||
|
||||
@Module
|
||||
@@ -21,9 +24,11 @@ annotation class IoDispatcher
|
||||
class DispatchersModule {
|
||||
@MainDispatcher
|
||||
@Provides
|
||||
@Singleton
|
||||
fun providesMainDispatcher(): CoroutineDispatcher = Dispatchers.Main
|
||||
|
||||
@IoDispatcher
|
||||
@Provides
|
||||
@Singleton
|
||||
fun providesIoDispatcher(): CoroutineDispatcher = Dispatchers.IO
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.github.nullptroma.wallenc.app.di.modules.data
|
||||
|
||||
import android.content.Context
|
||||
import com.github.nullptroma.wallenc.data.db.RoomFactory
|
||||
import com.github.nullptroma.wallenc.data.db.app.IAppDb
|
||||
import com.github.nullptroma.wallenc.data.db.app.dao.StorageKeyDao
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(dagger.hilt.components.SingletonComponent::class)
|
||||
class RoomModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideRoomFactory(@ApplicationContext appContext: Context) : RoomFactory {
|
||||
return RoomFactory(appContext)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideStorageKeyDao(database: IAppDb): StorageKeyDao {
|
||||
return database.storageKeyDao
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideAppDb(
|
||||
factory: RoomFactory
|
||||
): IAppDb {
|
||||
return factory.buildAppDb()
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package com.github.nullptroma.wallenc.app.di.modules.data
|
||||
import android.content.Context
|
||||
import com.github.nullptroma.wallenc.app.di.modules.app.IoDispatcher
|
||||
import com.github.nullptroma.wallenc.data.vaults.VaultsManager
|
||||
import com.github.nullptroma.wallenc.data.vaults.local.LocalVault
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IVaultsManager
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
@@ -18,14 +17,8 @@ import javax.inject.Singleton
|
||||
class SingletonModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideLocalVault(@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
@ApplicationContext context: Context): LocalVault {
|
||||
return LocalVault(ioDispatcher, context)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideVaultsManager(localVault: LocalVault): IVaultsManager {
|
||||
return VaultsManager(localVault)
|
||||
fun provideVaultsManager(@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
@ApplicationContext context: Context): IVaultsManager {
|
||||
return VaultsManager(ioDispatcher, context)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user