Created
May 23, 2020 20:39
-
-
Save Plnda/f610ae2f38d9c9fddc1b5235cf9a5a60 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
public struct Service { | |
public enum LifeCycle { | |
case global | |
case oneOf | |
} | |
/// Holds the lifecycle of the current service | |
public var cycle: LifeCycle | |
/// Unique name for each service | |
public let name: ObjectIdentifier | |
/// The closure that will resolve the service | |
private let resolve: (Dependencies) -> Any | |
var instance: Any? | |
func createInstance(d: Dependencies) -> Any { | |
return resolve(d) | |
} | |
/// Initialize a service with a resolver | |
public init<Service>(_ cycle: LifeCycle = .oneOf, _ resolve: @escaping (Dependencies) -> Service) { | |
self.name = ObjectIdentifier(Service.self) | |
self.resolve = resolve | |
self.cycle = cycle | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment