How do I use request params in my Mezzio app before the handler was initialized?

I am creating a Mezzio app which handles some POST-requests and uses some data from the body to get some configs from the DB (let’s say, I get the user’s id with some webhook and then by it get the configs I need to use in my app from the specific row in database). All these configs are needed to initialize different class objects to work with, while handling the request. Normally, if I didn’t need that data from the request, I would do something like that:

class WebhookHandlerFactory
{ // $config['client'] is hardcoded in the .env file in this case and then put into ConfigProvider
    protected ContainerInterface $container;

    public function __invoke(ContainerInterface $container): RequestHandlerInterface
    {
        $this->container = $container;
        $config = $this->getConfig();
        $client = (new SomeClient($config['client']))->getClient();
        $controller = (new SomeControllerFactory)($container);

        return new WebhookHandler($controller, $config, $client);
    }

    protected function getConfig(): ArrayObject
    {
        $config = $this->container->get('config');
        // here I use my hardcoded data to find something in the DB and then put it into $config

        return $config;
    }

The problem is that I cannot get my request body in the Factory.

The only way I found was making this factory return another factory which initializes handler class in __construct and then calls handle method like this:

public function __construct(
        ContainerInterface $container,
        CreateController $controller,
        ArrayObject $config
 ){
        $this->container = $container;
        $this->createController = $createController;
        $this->config = $config;

        $config = $this->getConfig();
        $client = (new SomeClient($config['client']))->getClient();

        $this->handler = new WebhookHandler($this->controller, $config, $client);
    }

    public function handle(ServerRequestInterface $request)
    {
        return $this->handler->handle($request);
    }

But my routes.php file now looks kinda ugly, having me thinking I’m doing something wrong.

return static function (Application $app): void
{
    $app->post('/', AppHandlerWebhookHandlerFactory::class);

My question is what is the more correct way to get my request data before handler initialization and which patterns I am better to use