Created
June 4, 2020 16:09
-
-
Save vedon/55ba79895db5b48d62a3619052befc80 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
protocol Service {} | |
Class ServiceLocator { | |
func register(_ service: Service, for type: ServiceType) | |
func resolve(_ type: ServiceType) | |
} | |
ServiceLocator.shared.register(UserSession(), type: UserService.self) | |
Struct UserService: Service {} | |
Class LoginViewController { | |
func login(_ name: String, password: String) { | |
let service = ServiceLocator.shared.resolve(UserService.self) | |
service.login(name, password) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment