Skip to content

Instantly share code, notes, and snippets.

@Plnda
Created May 23, 2020 20:39
Show Gist options
  • Save Plnda/f610ae2f38d9c9fddc1b5235cf9a5a60 to your computer and use it in GitHub Desktop.
Save Plnda/f610ae2f38d9c9fddc1b5235cf9a5a60 to your computer and use it in GitHub Desktop.
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