Skip to content

Instantly share code, notes, and snippets.

@vedon
Created June 4, 2020 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vedon/55ba79895db5b48d62a3619052befc80 to your computer and use it in GitHub Desktop.
Save vedon/55ba79895db5b48d62a3619052befc80 to your computer and use it in GitHub Desktop.
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