protected function createFromFactory($factory)
    {
        try {
            if (is_string($factory) && class_exists($factory)) {
                $factory = new $factory();
            }

            if (is_callable($factory)) {
                $service  = $factory($this);
            } else {
                throw new ContainerException(
                    'Service could not be created: "There were incorrectly '
                        . 'transmitted data when registering the service".'
                );
            }
        } catch (ContainerException $e) {
            throw $e;
        } catch (\Throwable $e) {
            throw new ContainerException(
                'Service could not be created: "Service factory may be '
                    . 'callable or string (that can be resolving to an '
                    . 'invokable class or to a FactoryInterface instance).'
            );
        }

        return $service;
    }