Наведён порядок в DI

This commit is contained in:
2026-05-18 18:29:32 +03:00
parent 03709d910b
commit fd6f2e5879
26 changed files with 283 additions and 315 deletions

View File

@@ -11,12 +11,10 @@ import javax.inject.Singleton
@Qualifier
@Retention(AnnotationRetention.BINARY)
@Singleton
annotation class MainDispatcher
@Qualifier
@Retention(AnnotationRetention.BINARY)
@Singleton
annotation class IoDispatcher
@Module

View File

@@ -1,4 +1,4 @@
package com.github.nullptroma.wallenc.app.di
package com.github.nullptroma.wallenc.app.di.modules.app
import com.github.nullptroma.wallenc.app.locale.AppLocaleControllerImpl
import com.github.nullptroma.wallenc.ui.locale.AppLocaleController

View File

@@ -10,10 +10,8 @@ import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
class SingletonModule {
object LoggerModule {
@Provides
@Singleton
fun provideLogger(): ILogger {
return Logger()
}
}
fun provideLogger(): ILogger = Logger()
}

View File

@@ -1,4 +1,4 @@
package com.github.nullptroma.wallenc.app.di
package com.github.nullptroma.wallenc.app.di.modules.app
import android.content.Context
import com.github.nullptroma.wallenc.ui.resources.UiStringResolver

View File

@@ -0,0 +1,51 @@
package com.github.nullptroma.wallenc.app.di.modules.data
import com.github.nullptroma.wallenc.app.di.modules.app.IoDispatcher
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.YandexDiskApiFactory
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.repository.YandexDiskRepositoryFactory
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.YandexUserInfoApi
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.YandexUserInfoApiFactory
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.repository.YandexUserInfoRepository
import com.github.nullptroma.wallenc.domain.vault.ports.YandexAccountStore
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {
@Provides
@Singleton
fun provideYandexUserInfoApi(): YandexUserInfoApi = YandexUserInfoApiFactory.create()
@Provides
@Singleton
fun provideYandexDiskApiFactory(
yandexAccountStore: YandexAccountStore,
@IoDispatcher ioDispatcher: CoroutineDispatcher,
): YandexDiskApiFactory = YandexDiskApiFactory(
accountRepository = yandexAccountStore,
ioDispatcher = ioDispatcher,
)
@Provides
@Singleton
fun provideYandexDiskRepositoryFactory(
apiFactory: YandexDiskApiFactory,
@IoDispatcher ioDispatcher: CoroutineDispatcher,
): YandexDiskRepositoryFactory = YandexDiskRepositoryFactory(
apiFactory = apiFactory,
ioDispatcher = ioDispatcher,
)
@Provides
@Singleton
fun provideYandexUserInfoRepository(
api: YandexUserInfoApi,
@IoDispatcher ioDispatcher: CoroutineDispatcher,
): YandexUserInfoRepository = YandexUserInfoRepository(api, ioDispatcher)
}

View File

@@ -0,0 +1,55 @@
package com.github.nullptroma.wallenc.app.di.modules.data
import com.github.nullptroma.wallenc.app.di.modules.app.IoDispatcher
import com.github.nullptroma.wallenc.domain.interfaces.IStorageSyncGroupStore
import com.github.nullptroma.wallenc.domain.vault.db.app.dao.StorageKeyMapDao
import com.github.nullptroma.wallenc.domain.vault.db.app.dao.StorageSyncGroupDao
import com.github.nullptroma.wallenc.domain.vault.db.app.dao.YandexAccountDao
import com.github.nullptroma.wallenc.domain.vault.db.app.repository.StorageKeyMapRepository
import com.github.nullptroma.wallenc.domain.vault.db.app.repository.StorageSyncGroupRepository
import com.github.nullptroma.wallenc.domain.vault.db.app.repository.YandexAccountRepository
import com.github.nullptroma.wallenc.domain.vault.ports.StorageKeyMapStore
import com.github.nullptroma.wallenc.domain.vault.ports.YandexAccountStore
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import javax.inject.Singleton
/**
* Room DAO/repository types live in `:infrastructure-android` under `domain.vault` packages.
*/
@Module
@InstallIn(SingletonComponent::class)
object PersistenceModule {
@Provides
@Singleton
fun provideStorageKeyMapRepository(
dao: StorageKeyMapDao,
@IoDispatcher ioDispatcher: CoroutineDispatcher,
): StorageKeyMapRepository = StorageKeyMapRepository(dao, ioDispatcher)
@Provides
@Singleton
fun provideStorageKeyMapStore(impl: StorageKeyMapRepository): StorageKeyMapStore = impl
@Provides
@Singleton
fun provideStorageSyncGroupStore(
dao: StorageSyncGroupDao,
@IoDispatcher ioDispatcher: CoroutineDispatcher,
): IStorageSyncGroupStore = StorageSyncGroupRepository(dao, ioDispatcher)
@Provides
@Singleton
fun provideYandexAccountRepository(
dao: YandexAccountDao,
@IoDispatcher ioDispatcher: CoroutineDispatcher,
): YandexAccountRepository = YandexAccountRepository(dao, ioDispatcher)
@Provides
@Singleton
fun provideYandexAccountStore(impl: YandexAccountRepository): YandexAccountStore = impl
}

View File

@@ -11,14 +11,16 @@ 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
/** Room types are implemented in `:infrastructure-android` with `domain.vault` packages. */
@Module
@InstallIn(dagger.hilt.components.SingletonComponent::class)
class RoomModule {
@InstallIn(SingletonComponent::class)
object RoomModule {
@Provides
@Singleton
fun provideRoomFactory(@ApplicationContext appContext: Context) : RoomFactory {
fun provideRoomFactory(@ApplicationContext appContext: Context): RoomFactory {
return RoomFactory(appContext)
}
@@ -48,9 +50,7 @@ class RoomModule {
@Provides
@Singleton
fun provideAppDb(
factory: RoomFactory
): IAppDb {
fun provideAppDb(factory: RoomFactory): IAppDb {
return factory.buildAppDb()
}
}

View File

@@ -1,169 +0,0 @@
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.domain.vault.db.app.dao.StorageKeyMapDao
import com.github.nullptroma.wallenc.domain.vault.db.app.dao.StorageMetaInfoDao
import com.github.nullptroma.wallenc.domain.vault.db.app.dao.StorageSyncGroupDao
import com.github.nullptroma.wallenc.domain.vault.db.app.dao.YandexAccountDao
import com.github.nullptroma.wallenc.domain.vault.db.app.repository.StorageKeyMapRepository
import com.github.nullptroma.wallenc.domain.vault.db.app.repository.StorageMetaInfoRepository
import com.github.nullptroma.wallenc.domain.vault.db.app.repository.StorageSyncGroupRepository
import com.github.nullptroma.wallenc.domain.vault.db.app.repository.YandexAccountRepository
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.YandexDiskApiFactory
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.repository.YandexDiskRepositoryFactory
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.YandexUserInfoApi
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.YandexUserInfoApiFactory
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.repository.YandexUserInfoRepository
import com.github.nullptroma.wallenc.domain.vault.ports.StorageKeyMapStore
import com.github.nullptroma.wallenc.domain.vault.ports.YandexAccountStore
import com.github.nullptroma.wallenc.task.runtime.TaskOrchestrator
import com.github.nullptroma.wallenc.domain.vault.vaults.VaultsManager
import com.github.nullptroma.wallenc.domain.vault.vaults.local.LocalVault
import com.github.nullptroma.wallenc.domain.interfaces.IUnlockManager
import com.github.nullptroma.wallenc.domain.interfaces.IStorageSyncGroupStore
import com.github.nullptroma.wallenc.domain.interfaces.IVault
import com.github.nullptroma.wallenc.domain.interfaces.IVaultsManager
import com.github.nullptroma.wallenc.domain.tasks.ITaskOrchestrator
import com.github.nullptroma.wallenc.vault.contract.VaultRegistrar
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
class SingletonModule {
@Provides
@Singleton
fun provideTaskOrchestrator(
@IoDispatcher ioDispatcher: CoroutineDispatcher,
): ITaskOrchestrator = TaskOrchestrator(ioDispatcher)
@Provides
@Singleton
fun provideYandexUserInfoApi(): YandexUserInfoApi = YandexUserInfoApiFactory.create()
@Provides
@Singleton
fun provideYandexDiskApiFactory(
yandexAccountStore: YandexAccountStore,
@IoDispatcher ioDispatcher: CoroutineDispatcher,
): YandexDiskApiFactory = YandexDiskApiFactory(
accountRepository = yandexAccountStore,
ioDispatcher = ioDispatcher,
)
@Provides
@Singleton
fun provideYandexDiskRepositoryFactory(
apiFactory: YandexDiskApiFactory,
@IoDispatcher ioDispatcher: CoroutineDispatcher,
): YandexDiskRepositoryFactory = YandexDiskRepositoryFactory(
apiFactory = apiFactory,
ioDispatcher = ioDispatcher,
)
@Provides
@Singleton
fun provideVaultsManager(
@IoDispatcher ioDispatcher: CoroutineDispatcher,
localVault: IVault,
keyRepo: StorageKeyMapStore,
yandexAccountStore: YandexAccountStore,
yandexUserInfoRepository: YandexUserInfoRepository,
yandexDiskRepositoryFactory: YandexDiskRepositoryFactory,
): VaultsManager {
return VaultsManager(
ioDispatcher = ioDispatcher,
localVault = localVault,
keyRepo = keyRepo,
yandexAccountStore = yandexAccountStore,
yandexUserInfoRepository = yandexUserInfoRepository,
yandexDiskRepositoryFactory = yandexDiskRepositoryFactory,
)
}
@Provides
@Singleton
fun provideLocalVault(
@IoDispatcher ioDispatcher: CoroutineDispatcher,
@ApplicationContext context: Context,
): IVault = LocalVault(
ioDispatcher = ioDispatcher,
vaultRoot = context.getExternalFilesDir("LocalVault"),
)
@Provides
@Singleton
fun provideIVaultsManager(impl: VaultsManager): IVaultsManager = impl
@Provides
@Singleton
fun provideVaultRegistrar(impl: VaultsManager): VaultRegistrar = impl
@Provides
fun provideUnlockManager(
vaultsManager: IVaultsManager
): IUnlockManager {
return vaultsManager.unlockManager
}
@Provides
@Singleton
fun provideStorageKeyMapRepository(
dao: StorageKeyMapDao,
@IoDispatcher ioDispatcher: CoroutineDispatcher
): StorageKeyMapRepository {
return StorageKeyMapRepository(dao, ioDispatcher)
}
@Provides
@Singleton
fun provideStorageKeyMapStore(
impl: StorageKeyMapRepository,
): StorageKeyMapStore = impl
@Provides
@Singleton
fun provideStorageMetaInfoRepository(
dao: StorageMetaInfoDao,
@IoDispatcher ioDispatcher: CoroutineDispatcher
): StorageMetaInfoRepository {
return StorageMetaInfoRepository(dao, ioDispatcher)
}
@Provides
@Singleton
fun provideStorageSyncGroupStore(
dao: StorageSyncGroupDao,
@IoDispatcher ioDispatcher: CoroutineDispatcher,
): IStorageSyncGroupStore = StorageSyncGroupRepository(dao, ioDispatcher)
@Provides
@Singleton
fun provideYandexAccountRepository(
dao: YandexAccountDao,
@IoDispatcher ioDispatcher: CoroutineDispatcher
): YandexAccountRepository {
return YandexAccountRepository(dao, ioDispatcher)
}
@Provides
@Singleton
fun provideYandexAccountStore(
impl: YandexAccountRepository,
): YandexAccountStore = impl
@Provides
@Singleton
fun provideYandexUserInfoRepository(
api: YandexUserInfoApi,
@IoDispatcher ioDispatcher: CoroutineDispatcher
): YandexUserInfoRepository {
return YandexUserInfoRepository(api, ioDispatcher)
}
}

View File

@@ -0,0 +1,22 @@
package com.github.nullptroma.wallenc.app.di.modules.data
import com.github.nullptroma.wallenc.app.di.modules.app.IoDispatcher
import com.github.nullptroma.wallenc.domain.tasks.ITaskOrchestrator
import com.github.nullptroma.wallenc.task.runtime.TaskOrchestrator
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object TaskModule {
@Provides
@Singleton
fun provideTaskOrchestrator(
@IoDispatcher ioDispatcher: CoroutineDispatcher,
): ITaskOrchestrator = TaskOrchestrator(ioDispatcher)
}

View File

@@ -0,0 +1,23 @@
package com.github.nullptroma.wallenc.app.di.modules.data
import com.github.nullptroma.wallenc.domain.interfaces.IVaultsManager
import com.github.nullptroma.wallenc.domain.vault.vaults.VaultsManager
import com.github.nullptroma.wallenc.vault.contract.VaultRegistrar
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
abstract class VaultBindingsModule {
@Binds
@Singleton
abstract fun bindVaultsManager(impl: VaultsManager): IVaultsManager
@Binds
@Singleton
abstract fun bindVaultRegistrar(impl: VaultsManager): VaultRegistrar
}

View File

@@ -0,0 +1,59 @@
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.domain.interfaces.IUnlockManager
import com.github.nullptroma.wallenc.domain.interfaces.IVault
import com.github.nullptroma.wallenc.domain.interfaces.IVaultsManager
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.repository.YandexDiskRepositoryFactory
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.repository.YandexUserInfoRepository
import com.github.nullptroma.wallenc.domain.vault.ports.StorageKeyMapStore
import com.github.nullptroma.wallenc.domain.vault.ports.YandexAccountStore
import com.github.nullptroma.wallenc.domain.vault.vaults.VaultsManager
import com.github.nullptroma.wallenc.domain.vault.vaults.local.LocalVault
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object VaultModule {
@Provides
@Singleton
fun provideLocalVault(
@IoDispatcher ioDispatcher: CoroutineDispatcher,
@ApplicationContext context: Context,
): IVault = LocalVault(
ioDispatcher = ioDispatcher,
// getExternalFilesDir may return null before storage is ready; LocalVault handles null root.
vaultRoot = context.getExternalFilesDir("LocalVault"),
)
@Provides
@Singleton
fun provideVaultsManager(
@IoDispatcher ioDispatcher: CoroutineDispatcher,
localVault: IVault,
keyRepo: StorageKeyMapStore,
yandexAccountStore: YandexAccountStore,
yandexUserInfoRepository: YandexUserInfoRepository,
yandexDiskRepositoryFactory: YandexDiskRepositoryFactory,
): VaultsManager = VaultsManager(
ioDispatcher = ioDispatcher,
localVault = localVault,
keyRepo = keyRepo,
yandexAccountStore = yandexAccountStore,
yandexUserInfoRepository = yandexUserInfoRepository,
yandexDiskRepositoryFactory = yandexDiskRepositoryFactory,
)
@Provides
@Singleton
fun provideUnlockManager(vaultsManager: IVaultsManager): IUnlockManager =
vaultsManager.unlockManager
}

View File

@@ -1,131 +1,18 @@
package com.github.nullptroma.wallenc.app.di.modules.domain
import com.github.nullptroma.wallenc.domain.interfaces.IUnlockManager
import com.github.nullptroma.wallenc.domain.interfaces.IStorageSyncEngine
import com.github.nullptroma.wallenc.domain.interfaces.IStorageSyncGroupStore
import com.github.nullptroma.wallenc.domain.tasks.ITaskOrchestrator
import com.github.nullptroma.wallenc.domain.interfaces.IVaultsManager
import com.github.nullptroma.wallenc.usecases.GetOpenedStoragesUseCase
import com.github.nullptroma.wallenc.usecases.FindStorageUseCase
import com.github.nullptroma.wallenc.usecases.ManageStoragesEncryptionUseCase
import com.github.nullptroma.wallenc.usecases.ManageTextSecretsUseCase
import com.github.nullptroma.wallenc.usecases.ManageTwoFaTokensUseCase
import com.github.nullptroma.wallenc.usecases.ManageVaultUseCase
import com.github.nullptroma.wallenc.usecases.RemoveStorageUseCase
import com.github.nullptroma.wallenc.usecases.RenameStorageUseCase
import com.github.nullptroma.wallenc.usecases.RunStorageSyncUseCase
import com.github.nullptroma.wallenc.usecases.ManageStorageSyncGroupsUseCase
import com.github.nullptroma.wallenc.usecases.StorageSyncEngine
import com.github.nullptroma.wallenc.usecases.StorageSyncReadiness
import com.github.nullptroma.wallenc.usecases.StorageFileManagementUseCase
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
class UseCasesModule {
@Provides
@Singleton
fun provideGetOpenedStoragesUseCase(unlockManager: IUnlockManager): GetOpenedStoragesUseCase {
return GetOpenedStoragesUseCase(unlockManager)
}
abstract class UseCasesModule {
@Provides
@Binds
@Singleton
fun provideManageVaultUseCase(vaultsManager: IVaultsManager): ManageVaultUseCase {
return ManageVaultUseCase(vaultsManager)
}
@Provides
@Singleton
fun provideFindStorageUseCase(vaultsManager: IVaultsManager): FindStorageUseCase {
return FindStorageUseCase(vaultsManager)
}
@Provides
@Singleton
fun provideStorageFileManagementUseCase(): StorageFileManagementUseCase {
return StorageFileManagementUseCase()
}
@Provides
@Singleton
fun provideRenameStorageUseCase(): RenameStorageUseCase {
return RenameStorageUseCase()
}
@Provides
@Singleton
fun provideManageStoragesEncryptionUseCase(
unlockManager: IUnlockManager,
): ManageStoragesEncryptionUseCase {
return ManageStoragesEncryptionUseCase(unlockManager)
}
@Provides
@Singleton
fun provideRemoveStorageUseCase(
vaultsManager: IVaultsManager,
unlockManager: IUnlockManager,
manageStoragesEncryptionUseCase: ManageStoragesEncryptionUseCase,
): RemoveStorageUseCase {
return RemoveStorageUseCase(vaultsManager, unlockManager, manageStoragesEncryptionUseCase)
}
@Provides
@Singleton
fun provideManageTwoFaTokensUseCase(): ManageTwoFaTokensUseCase {
return ManageTwoFaTokensUseCase()
}
@Provides
@Singleton
fun provideManageTextSecretsUseCase(): ManageTextSecretsUseCase {
return ManageTextSecretsUseCase()
}
@Provides
@Singleton
fun provideStorageSyncEngine(
vaultsManager: IVaultsManager,
groupStore: IStorageSyncGroupStore,
findStorageUseCase: FindStorageUseCase,
): IStorageSyncEngine = StorageSyncEngine(
vaultsManager = vaultsManager,
groupStore = groupStore,
findStorageUseCase = findStorageUseCase,
)
@Provides
@Singleton
fun provideManageStorageSyncGroupsUseCase(
groupStore: IStorageSyncGroupStore,
): ManageStorageSyncGroupsUseCase = ManageStorageSyncGroupsUseCase(groupStore)
@Provides
@Singleton
fun provideStorageSyncReadiness(
vaultsManager: IVaultsManager,
groupStore: IStorageSyncGroupStore,
findStorageUseCase: FindStorageUseCase,
): StorageSyncReadiness = StorageSyncReadiness(
vaultsManager = vaultsManager,
groupStore = groupStore,
findStorageUseCase = findStorageUseCase,
)
@Provides
@Singleton
fun provideRunStorageSyncUseCase(
orchestrator: ITaskOrchestrator,
syncEngine: IStorageSyncEngine,
syncReadiness: StorageSyncReadiness,
): RunStorageSyncUseCase = RunStorageSyncUseCase(
orchestrator = orchestrator,
syncEngine = syncEngine,
syncReadiness = syncReadiness,
)
}
abstract fun bindStorageSyncEngine(impl: StorageSyncEngine): IStorageSyncEngine
}