'TYPO3: Symfony command with arguments AND dependency injection

I made a command in TYPO3 which has arguments and dependency injection (DI). As I understood in symfony DI is made with the __construct method. But there I also have to state the argument which I want to pass to the command. So how is it done correctly?

Sources:

Versions: TYPO3 9.5.5, symfony 4.2.5

Say I want to pass one argument to the command AND inject the ObjectManager from TYPO3:

<?php

namespace Vendor\ExtensionName\Command;

use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use Symfony\Component\Console\Command\Command;

class SomeCommand extends Command 
{

    /**
     * Object Manager
     *
     * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
     */
    protected $objectManager;

    /**
     * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
     */
    public function __construct(
        string $cliParameter,
        \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) 
    {
        $this->cliParameter = $cliParameter;
        $this->objectManager = $objectManager;
    }
}

Then I call this with

bin/typo3 extension_name:someCommand foo

(where foo is the $cliParameter)

I get

Uncaught TYPO3 Exception Cannot instantiate interface TYPO3\CMS\Extbase\Object\ObjectManagerInterface

So my question is: What did I wrong? What's the correct way to do this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source