private function createInstanceFromFactory($factory)
    {   
        if ($factory instanceof ServiceFactoryInterface)
        {
            return $factory->create($this);
        }
        elseif ($factory instanceof Closure)
        {
            return $factory($this);
        }

        // otherwise throw an exception 
        throw new InvalidServiceException('Service could not be resolved, the registered factory is invalid.');
    }