Slim 4 dependencies how to set a container?

I have a Slim 3 REST API I am trying to move to slim 4, but I am confused about the dependencies.php. In slim 3 I use pdo like this:

// MySQL PDO
$container['pdo'] = function ($c) {
	$settings = $c->get('settings')['mysql'];
	$dsn = "mysql:dbname=" . $settings['dbname'] . ";host=". $settings['host'] .";charset=utf8";
	$pdo = new PDO($dsn, $settings['username'], $settings['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));
	$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	return $pdo;
};

I tried changing this for slim 4 but without luck. Can someone point me to the right direction?
slim 4 depnedencies.php

// Create Container using PHP-DI
$container = new Container();

// Set container to create App with on AppFactory
AppFactory::setContainer($container);
$app = AppFactory::create();

// MySQL PDO
$container->set('pdo', function ($c) {
    $settings = $c->get('settings')['mysql'];
$dsn = "mysql:dbname=" . $settings['dbname'] . ";host=". $settings['host'] .";charset=utf8";
$pdo = new PDO($dsn, $settings['username'], $settings['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $pdo;
});

Hi @leossmith

Your container has no definition for ‘settings’.

I would not recommend to call $container->set(...).

You can find more examples here:

Thank you, I ended up with a working copy:

$containerBuilder->addDefinitions([
    
    'pdo' => function (ContainerInterface $c) {
        $settings = $c->get('settings')['mysql'];
        $dsn = "mysql:dbname=" . $settings['dbname'] . ";host=". $settings['host'] .";charset=utf8";
        $pdo = new PDO($dsn, $settings['username'], $settings['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        return $pdo;
    } 
]);