TYPO3 Extbase - 依赖注入是否在服务中起作用 类?
TYPO3 Extbase - Does Dependency Injection work in Service Classes?
我正在使用 auth 类型的服务来添加基于 API 的登录。
我试图通过 @inject
使用 Extbase 的 FrontendUserRepository 添加用户。
但这是行不通的。
我是不是做错了什么,或者现在使用依赖注入还为时尚早?
P.S.: 我知道我可以通过以下方式使用存储库:
$objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
$this->frontendUserRepository = $objectManager->get('TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository');
带有 @Inject
注释的 DI 仅适用于由 TYPO3\CMS\Extbase\Object\ObjectManager 实例加载的对象。身份验证服务正在使用 GeneralUtility::makeInstanceService()
实例化,而 GeneralUtility::makeInstanceService()
又使用 GeneralUtility::makeInstance()
(参见 TYPO3\CMS\Core\Authentication\AbstractUserAuthentication::checkAuthentication()
),因此 @Inject
注释无效。
您必须使用您自己已经提到的解决方法。
[打字错误3 7.6]
我认为在 auth 服务中,所有 extbase 的东西都没有正确加载。我在 auth 服务中尝试使用 extbase repos 时遇到很多错误(在控制器的上下文中 运行 很棒)。我找到了一个 link 关于缺失部分的可能初始化:Extbase innerhalb eines TYPO3 Authentication Services verwenden
我正在使用 auth 类型的服务来添加基于 API 的登录。
我试图通过 @inject
使用 Extbase 的 FrontendUserRepository 添加用户。
但这是行不通的。
我是不是做错了什么,或者现在使用依赖注入还为时尚早?
P.S.: 我知道我可以通过以下方式使用存储库:
$objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
$this->frontendUserRepository = $objectManager->get('TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository');
带有 @Inject
注释的 DI 仅适用于由 TYPO3\CMS\Extbase\Object\ObjectManager 实例加载的对象。身份验证服务正在使用 GeneralUtility::makeInstanceService()
实例化,而 GeneralUtility::makeInstanceService()
又使用 GeneralUtility::makeInstance()
(参见 TYPO3\CMS\Core\Authentication\AbstractUserAuthentication::checkAuthentication()
),因此 @Inject
注释无效。
您必须使用您自己已经提到的解决方法。
[打字错误3 7.6] 我认为在 auth 服务中,所有 extbase 的东西都没有正确加载。我在 auth 服务中尝试使用 extbase repos 时遇到很多错误(在控制器的上下文中 运行 很棒)。我找到了一个 link 关于缺失部分的可能初始化:Extbase innerhalb eines TYPO3 Authentication Services verwenden