Furthermore, if I try to inject it in the constructor, I get this different error:
class SiteController extends Controller
{
protected $ds;
public function __construct(DatasourceInterface $ds)
{
$this->ds = $ds;
}
.
.
.
As I mentioned before, the interface dependency was declared in the web.php file and it actually works if I create the object out of the container manually.
PHP Recoverable Error – yii\base\ErrorException
Argument 1 passed to app\controllers\SiteController::__construct() must implement interface app\Contracts\DatasourceInterface, string given
DI doesn’t magically inject into controller actions. As for constructor, you seem to have changed constructor signature significantly. It should be, as far as I can see: