private function buildInstance(\ReflectionClass $reflection)
    {
        if (($constructor = $reflection->getConstructor()) === null) {
            return $reflection->newInstance();
        }
        $constructorParameters = [];
        foreach ($constructor->getParameters() as $parameter) {
            if (($parameterClass = $parameter->getClass()) === null) {
                throw new ContainerException(sprintf(
                    'Class "%s" constructor has a scalar / callable / array type parameter',
                    $reflection->getName()
                ));
            }
            $constructorParameters[] = $this->get($parameterClass->getName());
        }
        return $reflection->newInstanceArgs($constructorParameters);
    }