public function resolve(string $name, ?array $parameters = null)
    {
        if (isset($this->service[$name])) {
            return $this->service[$name];
        }

        if ($this->config->has($name)) {
            return $this->wrapService($name, $parameters);
        }

        if (null !== $this->parent_service) {
            $parents = array_merge([$name], class_implements($this->parent_service), class_parents($this->parent_service));

            if (in_array($name, $parents, true) && $this->parent_service instanceof $name) {
                return $this->parent_service;
            }
        }

        if (null !== $this->parent) {
            return $this->parent->resolve($name, $parameters);
        }

        throw new Exception\ServiceNotFound("service $name was not found in service tree");
    }