protected function resolveClass(string $class, array $primitives = [])
    {
        try {
            if (isset($this->constructorReflectionCache[$class])) {
                list($constructor, $parameters) = $this->constructorReflectionCache[$class];
            } else {
                $reflectionClass = new ReflectionClass($class);
                if (!$reflectionClass->isInstantiable()) {
                    throw new IocException(
                        sprintf(
                            '%s is not instantiable%s',
                            $class,
                            $this->currentTarget === null ? '' : " (dependency of {$this->currentTarget})"
                        )
                    );
                }

                $constructor = $reflectionClass->getConstructor();
                $parameters = $constructor !== null ? $constructor->getParameters() : null;
                $this->constructorReflectionCache[$class] = [$constructor, $parameters];
            }

            if ($constructor === null) {
                // No constructor, so instantiating is easy
                return new $class;
            }

            $constructorParameters = $this->resolveParameters($class, $parameters, $primitives);

            return new $class(...$constructorParameters);
        } catch (ReflectionException $ex) {
            throw new IocException("Failed to resolve class $class", 0, $ex);
        }
    }