我正在使用 TYPO3 10.2 并嘗試將我創建的一些服務類注入到我的身份驗證服務中。class AuthService extends \TYPO3\CMS\Core\Authentication\AuthenticationServiceAuthService 中的構造函數: /** * Contains the configuration of the current extension * @var ConfigurationService */ protected $configurationService; /** * @var RestClientService */ protected $restClientService; /** * @var ConnectionPool */ protected $connectionPool; /** * * @param ConfigurationService $configurationService * @param RestClientService $restClientService * @param ConnectionPool $connectionPool */ public function __construct(ConfigurationService $configurationService, RestClientService $restClientService, ConnectionPool $connectionPool) { $this->configurationService = $configurationService; $this->restClientService = $restClientService; $this->connectionPool = $connectionPool; }我收到以下錯誤:函數 Vendor\MyExt\Service\AuthService::__construct() 的參數太少,第 3461 行的 C:\xampp\htdocs\myproject\typo3\sysext\core\Classes\Utility\GeneralUtility.php 中傳遞了 0,而預期為 3有什么建議嗎?我在 ControllerClass 中使用了相同的構造函數,并且在那里一切正常。到目前為止感謝!
1 回答

波斯汪
TA貢獻1811條經驗 獲得超4個贊
看起來您AuthenticationService的內部實例化為GeneralUtility::makeInstance(). 對于您在某些時候注冊的許多類都是如此,然后 TYPO3 負責創建類(想想用戶函數、插件控制器、模塊控制器、身份驗證服務、掛鉤等)。
GeneralUtility::makeInstance()需要將類從 DI 容器中取出以使 DI 工作,但這僅適用于public在容器編譯期間創建的類。
出于這個原因,您的問題的解決方案應該是AuthService在您的Configuration/Services.yaml:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
Vendor\MyExt\:
resource: '../Classes/*'
Vendor\MyExt\Service\AuthService:
public: true
- 1 回答
- 0 關注
- 124 瀏覽
添加回答
舉報
0/150
提交
取消