       DefinitionKey(protocolType: $0, argumentsType: key.argumentsType, associatedTag: key.associatedTag)
     })
     for key in [key] + keys {
-      if let previouslyResolved: T = resolvedInstances.previouslyResolvedInstance(forKey: key, inScope: definition.scope) {
+      if let previouslyResolved = resolvedInstances[forKey: key, inScope: definition.scope] as? T {
         return previouslyResolved
       }
     }

  var singletons = [DefinitionKey: Any]()
  var resolvableInstances = [Resolvable]()
  
  func storeResolvedInstance<T>(instance: T, forKey key: DefinitionKey, inScope scope: ComponentScope) {
    switch scope {
    case .Singleton, .EagerSingleton: singletons[key] = instance
    case .ObjectGraph: resolvedInstances[key] = instance
    case .Prototype: break
    }
  }
  
  func previouslyResolvedInstance<T>(forKey key: DefinitionKey, inScope scope: ComponentScope) -> T? {
    switch scope {
    case .Singleton, .EagerSingleton: return singletons[key] as? T
    case .ObjectGraph: return resolvedInstances[key] as? T
    case .Prototype: return nil
    }
  }
  

      return previouslyResolved
    }

    resolvedInstances[forKey: key, inScope: definition.scope] = resolvedInstance

    if let resolvable = resolvedInstance as? Resolvable {
      resolvedInstances.resolvableInstances.append(resolvable)
