 */
 
 import Foundation
+
+public enum Lifecycle {
+    case NotCached
+    case Cached
+    case OneTime
+}
 
 /**
  A simple, elegant, flexible dependency resolver.

    
    private class Dependency {
        private let create: Any -> Any
        private let cached: Bool
        private var instance: Any?
        
        init<P, D>(cached: Bool, create: P -> D) {
            self.cached = cached
            self.create = { param in create(param as! P) }
        }
        
        func resolve<P, D>(parameters: P, cached: Bool) -> D {
            var result: D
            if cached && self.cached {
                if instance == nil {
                    instance = create(parameters)
                }

    public static func resolve<P, D>(parameters: P, type: String = String(reflecting: D.self), name: String? = nil, cached: Bool = true) -> D? {
        let key = Key(type: type, name: name)
        guard let dependency = dependencies[key] else { return nil }
        defer {
            if dependency.lifecycle == .OneTime {
                unregister(key)
            }
        }
        return (dependency.resolve(parameters, cached: cached) as D)
    }
    
