protected function createObjectUsingFactory(string $typeName, Factory $factory, ?bool $nullable = false): ?object
    {
        $this->underConstruction[$typeName] = true;
        
        try {
            // Assemble arguments and scope config objects to the bound type:
            $object = ($factory->callback)(...$this->populateArguments($factory->getReflection(), null, $typeName));
            
            if (!$object instanceof $typeName) {
                if ($object === null && $nullable) {
                    return null;
                }
                
                $type = \is_object($object) ? \get_class($object) : \gettype($object);
                
                throw new ContainerException(\sprintf('Factory must return an instance of %s, returned value is %s', $typeName, $type));
            }
        } finally {
            unset($this->underConstruction[$typeName]);
        }
        
        return $object;
    }