[TYPO3-mvc] confusion with object manager in CommandController context

Lorenz Ulrich lorenz-typo3 at visol.ch
Fri Jan 25 09:27:01 CET 2013


Hi Domi

Using TYPO3 4.7, I have no problem using DI in a CommandController.

Just use the @inject annotation for the repositories you want to use.

And you shouldn't use makeInstance anymore but use the objectManager instead

$this->sendmailService = 
$this->objectManager->create('Tx_Intranet_Service_SendMailService');

(The object manager can also be injected with DI.)

Could it be a caching problem?

Best regards,

Lorenz

Am 25.01.2013 04:57, schrieb Domi:
  Hello,
>
> I need some hints how to resolve following issue:
>
> I built CommandController class for sending mails as scheduler task.
> Here I recognized, that I can't use dependency injection out of the box,
> I need to inject several repositories and services.
>
> How do I resolve this?
> Currently I do:
> $this->clientRepository =
> t3lib_div::makeInstance('Tx_Intranet_Domain_Repository_ClientRepository');
> $this->frontendUserGroupRepository =
> t3lib_div::makeInstance('Tx_Extbas>e_Domain_Repository_FrontendUserGroupRepository');
>
> $this->sendMailService =
> t3lib_div::makeInstance('Tx_Intranet_Service_SendMailService');
>
> How do I need to use the object manager that I can make use of DI?
>
> In the next step I call my SendMailService, which uses a lot the feature
> of DI. But now all my functions fail because of the call through the
> command controller.
>
> ERROR: call to a member function xxx on a non-object...
>
> How can I register my CommandController class, that he can use same
> classes as my frontend?
>
> Thanks for any information about this.
>
> Dominic



More information about the TYPO3-project-typo3v4mvc mailing list