Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import Foundation
class ImageProvider {
typealias Dependencies = HasPersistanceProvider
let dependencies: Dependencies
init(dependencies: Dependencies) {
self.dependencies = dependencies
dependencies.persistanceProvider.store()
}
}
class ArticlesProvider {}
class PersistanceProvider {
func store() {
}
}
protocol HasImageProvider {
var imageProvider: ImageProvider { get }
}
protocol HasArticleProvider {
var articleProvider: ArticlesProvider { get }
}
protocol HasPersistanceProvider {
var persistanceProvider: PersistanceProvider { get }
}
class FooCoordinator {
typealias Dependencies = HasImageProvider & HasArticleProvider
let dependencies: Dependencies
init(dependencies: Dependencies) {
self.dependencies = dependencies
}
}
struct AppDependency: HasImageProvider, HasArticleProvider, HasPersistanceProvider {
let imageProvider: ImageProvider
let articleProvider: ArticlesProvider
let persistanceProvider: PersistanceProvider
}
struct ImageProviderDependency: HasPersistanceProvider {
let persistanceProvider: PersistanceProvider
}
let articleProvider = ArticlesProvider()
let persistanceProvider = PersistanceProvider()
let imageProviderDeps = ImageProviderDependency(persistanceProvider: persistanceProvider)
let imageProvider = ImageProvider(dependencies: imageProviderDeps)
let appDeps = AppDependency(imageProvider:imageProvider, articleProvider:articleProvider, persistanceProvider:persistanceProvider)
let coordinator = FooCoordinator(dependencies: appDeps)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment