public function resolve($name, $args = array())
    {
        if ($this->container->has($name)) {
            return $this->container->get($name);
        }

        if (!class_exists($name)) {
            throw new \InvalidArgumentException(
                "$name is not a defined class or container service name."
            );
        }

        $reflection = new \ReflectionClass($name);
        $constructor = $reflection->getConstructor();
        if (is_null($constructor)) {
            return $reflection->newInstanceWithoutConstructor();
        }
        $params = $constructor->getParameters();
        $classes = array();
        foreach ($params as $param) {
            $class = $param->getClass();
            $arg = null;
            if (is_null($class)) {
                if (isset($args[$param->name])) {
                    $arg = $args[$param->name];
                }
            } else {
                $arg = $this->container->get($class->name);
            }
            $classes[] = $arg;
        }
        return $reflection->newInstanceArgs($classes);
    }