     }
     
     public final func weakShared<T: AnyObject>(name: String = #function, _ factory: @autoclosure () -> T, configure: ((T) -> Void)? = nil) -> T {
-        return inject(
-            lifecyle: .WeakShared,
+        var instance: T! // Keep instance alive for duration of method
+        let weakInstance: Weak<T> = inject(
+            lifecyle: .weakShared,
             name: name,
-            instancePool: &weakSharedInstances,
-            containerFactory: { WeakContainer(instance: $0) },
-            factory: factory,
-            configure: configure
+            instances: &weakSharedInstances,
+            factory: {
+                instance = factory()
+                return Weak(instance)
+            },
+            configure: { configure?($0.instance!) }
         )
+        return weakInstance.instance!
     }
     
     public final func unshared<T>(name: String = #function, factory: () -> T, configure: ((T) -> Void)? = nil) -> T {

        let instance = factory()
        instanceStack.removeLast()
        
        let container = containerFactory(instance)
        instancePool[name] = container
        
        if let configure = configure {
            configureStack.append({configure(instance)})

    
    public final func scoped<T>(name: String = #function, _ factory: @autoclosure () -> T, configure: ((T) -> Void)? = nil) -> T {
        return inject(
            lifecyle: .scoped,
            name: name,
            instances: &scopedInstances,
            factory: factory,
            configure: configure
        )
    }
    
    private final func inject<T>(lifecyle: Lifecyle, name: String, instances: inout [String:Any], factory: () -> T, configure: ((T) -> Void)?) -> T {
        if let instance = instances[name] as? T {
            return instance
        }
        
        let key = InstanceKey(lifecycle: lifecyle, name: name)
        
        if lifecyle != .unshared && instanceStack.contains(key) {
            fatalError("Circular dependency from one of \(instanceStack) to \(key) in initializer")
        }
        
