I've just started using Slim 4 (also brand new to Slim as a whole) and after reading up and following some articles I've managed to get a skeleton app setup with a PDO connection to the DB.
I'm now looking to inject a second PDO instance so that a second database can be used based on the request, though I'm struggling to get my head around how to do this.
My current setup is:
settings.php
$settings['db'] = [
    'driver' => 'mysql',
    'host' => 'database',
    'username' => 'root',
    'database' => 'demo',
    'password' => 'password',
    'flags' => [
        // Turn off persistent connections
        PDO::ATTR_PERSISTENT => false,
        // Enable exceptions
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        // Emulate prepared statements
        PDO::ATTR_EMULATE_PREPARES => true,
        // Set default fetch mode to array
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    ],
];
container.php
return [
    Configuration::class => function () {
        return new Configuration(require __DIR__ . '/settings.php');
    },
    App::class => function (ContainerInterface $container) {
        AppFactory::setContainer($container);
        $app = AppFactory::create();
        return $app;
    },
    PDO::class => function (ContainerInterface $container) {
        $config = $container->get(Configuration::class);
        $host = $config->getString('db.host');
        $dbname =  $config->getString('db.database');
        $username = $config->getString('db.username');
        $password = $config->getString('db.password');
        $dsn = "mysql:host=$host;dbname=$dbname;";
        return new PDO($dsn, $username, $password);
    },
];
Example usage in repository
class UserReaderRepository
{
    /**
     * @var PDO The database connection
     */
    private $connection;
    /**
     * Constructor.
     *
     * @param PDO $connection The database connection
     */
    public function __construct(PDO $connection)
    {
        $this->connection = $connection;
    }
    /**
     * Get user by the given user id.
     *
     * @throws DomainException
     *
     * @return array The user data
     */
    public function getUsers(): array
    {
        $sql = "SELECT user_id, title, firstname, surname, email_address FROM user us;";
        $statement = $this->connection->prepare($sql);
        $statement->execute();
From what I can tell, the PDO class itself is instantiated within container.php - how do i modify this as to instantiate 2 separate PDO classes - and how do i use them within repositories later on?
For clarity, I've tried looking at How to set up and inject multiple PDO database connections in slim 4? but I don't quite understand where to define the PDO classes. I've also looked here which didn't seem to help - I don't have a dependencies.php, the closest I have is middleware.php but when I try this I get the error Uncaught Error: Cannot use object of type DI\Container as array in /var/www/config/middleware.php:
return function (App $app) {
    // Parse json, form data and xml
    $app->addBodyParsingMiddleware();
    // Add global middleware to app
    $app->addRoutingMiddleware();
    $container = $app->getContainer();
    // PDO database library
    $container['db'] = function ($c) {
        $settings = $c->get('settings')['db'];
        $pdo = new PDO("mysql:host=" . $settings['host'] . ";dbname=" . $settings['dbname'],
            $settings['user'], $settings['pass']);
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
        return $pdo;
    };
    // Error handler
    $settings = $container->get(Configuration::class)->getArray('error_handler_middleware');
    $display_error_details = (bool)$settings['display_error_details'];
    $log_errors = (bool)$settings['log_errors'];
    $log_error_details = (bool)$settings['log_error_details'];
    $app->addErrorMiddleware($display_error_details, $log_errors, $log_error_details);
};