Skip to content

Commit

Permalink
Merge pull request #3966 from owncloud/koin_dsl
Browse files Browse the repository at this point in the history
Koin dsl
  • Loading branch information
JuancaG05 authored Oct 3, 2023
2 parents 824514b + 78bb01c commit e6a65c0
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @author Abel García de Prada
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2022 ownCloud GmbH.
* Copyright (C) 2023 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand Down Expand Up @@ -49,6 +49,9 @@ import com.owncloud.android.data.transfers.datasources.implementation.OCLocalTra
import com.owncloud.android.data.user.datasources.LocalUserDataSource
import com.owncloud.android.data.user.datasources.implementation.OCLocalUserDataSource
import org.koin.android.ext.koin.androidContext
import org.koin.core.module.dsl.factoryOf
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.bind
import org.koin.dsl.module

val localDataSourceModule = module {
Expand All @@ -57,22 +60,22 @@ val localDataSourceModule = module {
single { OwncloudDatabase.getDatabase(androidContext()).appRegistryDao() }
single { OwncloudDatabase.getDatabase(androidContext()).capabilityDao() }
single { OwncloudDatabase.getDatabase(androidContext()).fileDao() }
single { OwncloudDatabase.getDatabase(androidContext()).shareDao() }
single { OwncloudDatabase.getDatabase(androidContext()).userDao() }
single { OwncloudDatabase.getDatabase(androidContext()).folderBackUpDao() }
single { OwncloudDatabase.getDatabase(androidContext()).transferDao() }
single { OwncloudDatabase.getDatabase(androidContext()).shareDao() }
single { OwncloudDatabase.getDatabase(androidContext()).spacesDao() }
single { OwncloudDatabase.getDatabase(androidContext()).transferDao() }
single { OwncloudDatabase.getDatabase(androidContext()).userDao() }

single<SharedPreferencesProvider> { OCSharedPreferencesProvider(get()) }
singleOf(::OCSharedPreferencesProvider) bind SharedPreferencesProvider::class
single<LocalStorageProvider> { ScopedStorageProvider(dataFolder, androidContext()) }

factory<LocalAppRegistryDataSource> { OCLocalAppRegistryDataSource(get()) }
factory<LocalAuthenticationDataSource> { OCLocalAuthenticationDataSource(androidContext(), get(), get(), accountType) }
factory<LocalCapabilitiesDataSource> { OCLocalCapabilitiesDataSource(get()) }
factory<LocalFileDataSource> { OCLocalFileDataSource(get()) }
factory<LocalShareDataSource> { OCLocalShareDataSource(get()) }
factory<LocalUserDataSource> { OCLocalUserDataSource(get()) }
factory<FolderBackupLocalDataSource> { OCFolderBackupLocalDataSource(get()) }
factory<LocalTransferDataSource> { OCLocalTransferDataSource(get()) }
factory<LocalSpacesDataSource> { OCLocalSpacesDataSource(get()) }
factoryOf(::OCFolderBackupLocalDataSource) bind FolderBackupLocalDataSource::class
factoryOf(::OCLocalAppRegistryDataSource) bind LocalAppRegistryDataSource::class
factoryOf(::OCLocalCapabilitiesDataSource) bind LocalCapabilitiesDataSource::class
factoryOf(::OCLocalFileDataSource) bind LocalFileDataSource::class
factoryOf(::OCLocalShareDataSource) bind LocalShareDataSource::class
factoryOf(::OCLocalSpacesDataSource) bind LocalSpacesDataSource::class
factoryOf(::OCLocalTransferDataSource) bind LocalTransferDataSource::class
factoryOf(::OCLocalUserDataSource) bind LocalUserDataSource::class
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,32 @@ import com.owncloud.android.lib.resources.status.services.implementation.OCServe
import com.owncloud.android.lib.resources.webfinger.services.WebFingerService
import com.owncloud.android.lib.resources.webfinger.services.implementation.OCWebFingerService
import org.koin.android.ext.koin.androidContext
import org.koin.core.module.dsl.factoryOf
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.bind
import org.koin.dsl.module

val remoteDataSourceModule = module {
single { ConnectionValidator(androidContext(), androidContext().resources.getBoolean(R.bool.clear_cookies_on_validation)) }
single { ClientManager(get(), get(), androidContext(), MainApp.accountType, get()) }

single<ServerInfoService> { OCServerInfoService() }
single<OIDCService> { OCOIDCService() }
single<WebFingerService> { OCWebFingerService() }
singleOf(::OCServerInfoService) bind ServerInfoService::class
singleOf(::OCOIDCService) bind OIDCService::class
singleOf(::OCWebFingerService) bind WebFingerService::class

single<RemoteAppRegistryDataSource> { OCRemoteAppRegistryDataSource(get()) }
single<RemoteAuthenticationDataSource> { OCRemoteAuthenticationDataSource(get()) }
single<RemoteCapabilitiesDataSource> { OCRemoteCapabilitiesDataSource(get(), get()) }
single<RemoteFileDataSource> { OCRemoteFileDataSource(get()) }
single<RemoteOAuthDataSource> { OCRemoteOAuthDataSource(get(), get()) }
single<RemoteServerInfoDataSource> { OCRemoteServerInfoDataSource(get(), get()) }
single<RemoteShareDataSource> { OCRemoteShareDataSource(get(), get()) }
single<RemoteShareeDataSource> { OCRemoteShareeDataSource(get(), get()) }
single<RemoteSpacesDataSource> { OCRemoteSpacesDataSource(get()) }
single<RemoteUserDataSource> {
OCRemoteUserDataSource(get(), androidContext().resources.getDimension(R.dimen.file_avatar_size).toInt())
}
single<RemoteWebFingerDatasource> { OCRemoteWebFingerDatasource(get(), get()) }
singleOf(::OCRemoteAppRegistryDataSource) bind RemoteAppRegistryDataSource::class
singleOf(::OCRemoteAuthenticationDataSource) bind RemoteAuthenticationDataSource::class
singleOf(::OCRemoteCapabilitiesDataSource) bind RemoteCapabilitiesDataSource::class
singleOf(::OCRemoteFileDataSource) bind RemoteFileDataSource::class
singleOf(::OCRemoteOAuthDataSource) bind RemoteOAuthDataSource::class
singleOf(::OCRemoteServerInfoDataSource) bind RemoteServerInfoDataSource::class
singleOf(::OCRemoteShareDataSource) bind RemoteShareDataSource::class
singleOf(::OCRemoteShareeDataSource) bind RemoteShareeDataSource::class
singleOf(::OCRemoteSpacesDataSource) bind RemoteSpacesDataSource::class
singleOf(::OCRemoteWebFingerDatasource) bind RemoteWebFingerDatasource::class
single<RemoteUserDataSource> { OCRemoteUserDataSource(get(), androidContext().resources.getDimension(R.dimen.file_avatar_size).toInt()) }

factory { RemoteCapabilityMapper() }
factory { RemoteShareMapper() }
factory { RemoteShareeMapper() }
factoryOf(::RemoteCapabilityMapper)
factoryOf(::RemoteShareMapper)
factoryOf(::RemoteShareeMapper)
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,22 @@ import com.owncloud.android.domain.spaces.SpacesRepository
import com.owncloud.android.domain.transfers.TransferRepository
import com.owncloud.android.domain.user.UserRepository
import com.owncloud.android.domain.webfinger.WebFingerRepository
import org.koin.core.module.dsl.factoryOf
import org.koin.dsl.bind
import org.koin.dsl.module

val repositoryModule = module {
factory<AppRegistryRepository> { OCAppRegistryRepository(get(), get(), get()) }
factory<AuthenticationRepository> { OCAuthenticationRepository(get(), get()) }
factory<CapabilityRepository> { OCCapabilityRepository(get(), get(), get()) }
factory<FileRepository> { OCFileRepository(get(), get(), get(), get()) }
factory<ServerInfoRepository> { OCServerInfoRepository(get(), get(), get()) }
factory<ShareRepository> { OCShareRepository(get(), get()) }
factory<ShareeRepository> { OCShareeRepository(get()) }
factory<SpacesRepository> { OCSpacesRepository(get(), get()) }
factory<UserRepository> { OCUserRepository(get(), get()) }
factory<OAuthRepository> { OCOAuthRepository(get()) }
factory<FolderBackupRepository> { OCFolderBackupRepository(get()) }
factory<WebFingerRepository> { OCWebFingerRepository(get()) }
factory<TransferRepository> { OCTransferRepository(get()) }

factoryOf(::OCAppRegistryRepository) bind AppRegistryRepository::class
factoryOf(::OCAuthenticationRepository) bind AuthenticationRepository::class
factoryOf(::OCCapabilityRepository) bind CapabilityRepository::class
factoryOf(::OCFileRepository) bind FileRepository::class
factoryOf(::OCFolderBackupRepository) bind FolderBackupRepository::class
factoryOf(::OCOAuthRepository) bind OAuthRepository::class
factoryOf(::OCServerInfoRepository) bind ServerInfoRepository::class
factoryOf(::OCShareRepository) bind ShareRepository::class
factoryOf(::OCShareeRepository) bind ShareeRepository::class
factoryOf(::OCSpacesRepository) bind SpacesRepository::class
factoryOf(::OCTransferRepository) bind TransferRepository::class
factoryOf(::OCUserRepository) bind UserRepository::class
factoryOf(::OCWebFingerRepository) bind WebFingerRepository::class
}
Loading

0 comments on commit e6a65c0

Please sign in to comment.