private function createServiceFromFactory(string $name, array $options = null)
    {
        $factory = $this->factories[$name] ?? null;

        if (is_string($factory) && class_exists($factory)) {
            $factory = new $factory();
            if ($factory instanceof FactoryInterface) {
                $this->factories[$name] = $factory;
                return $factory($this->creationContext, $name, $options);
            }
            throw InvalidArgumentException::fromInvalidFactory($factory);
        }

        if (is_callable($factory)) {
            return $factory($this->creationContext, $name, $options);
        } elseif (isset($this->invokables[$name])) {
            $invokable = $this->invokables[$name];
            return $options === null ? new $invokable() : new $invokable($options);
        }

        foreach ($this->abstractFactories as $idx => $abstractFactory) {
            if ($abstractFactory->canCreate($this->creationContext, $name)) {
                return $abstractFactory($this->creationContext, $name, $options);
            }
        }

        throw ServiceNotFoundException::fromUnknownService($name);
    }