Dependency Injection not working in BE Ajax Call

I have a problem calling a ControllerAction using Ajax. Calling and Response are working well, but in the called Controller the DI isn'nt working. All Injected Services/Repos are empty (NULL).

The only way how to it get working was to call the ObjectManager and initialize each Service/Repo directly in the Action:

$this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
$this->resourceFactory = $this->objectManager->get('\TYPO3\CMS\Core\Resource\ResourceFactory'

Is there a simple way to get DI working on Ajax Calls?

Upvotes: 2

Views: 459

Answers (1)

Jost
Jost

Reputation: 5840

DI only works if the object is created by an ObjectManager, and objects are only created by an ObjectManager in an Extbase context or manually.

So assuming BE AJAX calls are not done in an Extbase context (not sure about that), you are using the correct way to initialize you objects.

Upvotes: 3

Related Questions