Skip to content

Instantly share code, notes, and snippets.

@Winchariot
Created December 4, 2017 17:02
Show Gist options
  • Save Winchariot/f85de57bc4e3f6ecf184b650cc99d9f0 to your computer and use it in GitHub Desktop.
Save Winchariot/f85de57bc4e3f6ecf184b650cc99d9f0 to your computer and use it in GitHub Desktop.
Simple class-level Dependency Injection
//By separating the convenience init into its own file, you can instantiate ClientClass() easily in your project.
// Your unit tests only need to include the ClientClass.swift source and not this init
extension ClientClass {
convenience init() {
self.init(myDependency: MyDependencyConcreteImplementation())
}
}
final class ClientClass {
private let myDependency: MyDependencyProtocol
init(myDependency: MyDependencyProtocol) {
self.myDependency = myDependency
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment