Last active
May 23, 2020 21:01
-
-
Save Plnda/91523f31dc1990caf3bc16644d258025 to your computer and use it in GitHub Desktop.
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
/// Private extension | |
private extension Dependencies { | |
/// Resolve a serice based on its ObjectIdentifier | |
func resolve<Service>() -> Service { | |
var service = self.factories[ObjectIdentifier(Service.self)]! | |
guard let instance = service.instance, service.cycle == .global else { | |
service.instance = service.createInstance(d: self) | |
self.factories[service.name] = service | |
return service.instance as! Service | |
} | |
return instance as! Service | |
} | |
/// Register a service with our resolver | |
private func register(_ service: Service) { | |
self.factories[service.name] = service | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment