   }
 
   private func resolveSingle<T, Method>(_ container: DIContainer, pair: RTypeWithName, method: @escaping (Method) -> Any) throws -> T {
-    if let obj = Cache.single[pair.uniqueKey] {
-      return obj as! T
-    }
-
-    let obj: T = try resolvePerDependency(container, pair: pair, method: method)
-    Cache.single[pair.uniqueKey] = obj
-    return obj
+    return try _resolveUniversal(container, pair: pair, method: method,
+                                 get: { Cache.single[$0] },
+                                 set: { Cache.single[$0] = $1 })
   }
   
   private func resolveWeakSingle<T, Method>(_ container: DIContainer, pair: RTypeWithName, method: @escaping (Method) -> Any) throws -> T {

	func check<T>(name: String, type: T.Type) throws -> [RTypeFinal] {
		let rTypes = try getTypes(type)
		
		if !rTypes.contains(where: { $0.has(name: name)}) {
			throw DIError.typeIsNotFoundForName(type: type, name: name, typesInfo: rTypes.map { $0.typeInfo })
		}
		

      Cache.weakSingle.removeValue(forKey: data.key)
    }
    
    return try _resolveUniversal(container, pair: pair, method: method,
                                 get: { Cache.weakSingle[$0]?.value },
                                 set: { Cache.weakSingle[$0] = Weak(value: $1) })
  }

  private func resolvePerScope<T, Method>(_ container: DIContainer, pair: RTypeWithName, method: @escaping (Method) -> Any) throws -> T {
    return try _resolveUniversal(container, pair: pair, method: method,
                                 get: { container.scope[$0] },
                                 set: { container.scope[$0] = $1 })
  }
  
  private func _resolveUniversal<T, Method>(_ container: DIContainer, pair: RTypeWithName, method: @escaping (Method) -> Any,
                                get: (_: RType.UniqueKey)->Any?, set: (_:RType.UniqueKey, _:T)->()) throws -> T {
    if let obj = get(pair.uniqueKey) {
      return obj as! T
    }
    
    let obj: T = try resolvePerDependency(container, pair: pair, method: method)
    set(pair.uniqueKey, obj)
    return obj
  }

