Created
December 4, 2017 17:02
-
-
Save Winchariot/f85de57bc4e3f6ecf184b650cc99d9f0 to your computer and use it in GitHub Desktop.
Simple class-level Dependency Injection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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()) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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