[TYPO3-mvc] Dependency Injection not working

Alexander Dick typo3 at dick.at
Wed Feb 1 10:14:58 CET 2012


Hi Claus,

thanks, it works now - after clearing the cache in the backend... I'm on 
4.6.

Sometimes the solution is too simple to be true ;-)

Thank you!
Alex

Am 01.02.2012 10:04, schrieb Claus Due:
> Hi Alex,
>
> 1) Did you clear the object reflection cache? If you're on 4.5 you must do this manually. If the error has been happening for more than an hour then this is -not- the cause.
>
> 2) Does ApplicantRepository implement t3lib_Singleton? It should, if you wish to utilize injection.
>
> 3) If none of the above then are you able to manually construct an instance of ApplicantRepository using ObjectManager?
>
> --
> Cheers,
> Claus
> http://fedext.net
>
> On Feb 1, 2012, at 9:27 AM, Alexander Dick wrote:
>
>> Hi everyone,
>>
>> I have a question regarding dependency injection.
>>
>> Can't I inject any random Repository in my Controller?
>>
>> class Tx_Xxx_Controller_ApplicationController extends Tx_Extbase_MVC_Controller_ActionController {
>>
>> 	/**
>> 	 * @var Tx_Xxx_Domain_Repository_ApplicationRepository
>> 	 */
>> 	protected $applicationRepository;
>>
>> 	/**
>> 	 * @var Tx_Xxx_Domain_Repository_ApplicantRepository
>> 	 */
>> 	protected $applicantRepository;
>>
>> 	
>> 	/**
>> 	 * ApplicationRepository - works as expected
>> 	 *
>> 	 * @param Tx_Xxx_Domain_Repository_ApplicationRepository $applicationRepository
>> 	 * @return void
>> 	 */
>> 	public function injectApplicationRepository(Tx_Xxx_Domain_Repository_ApplicationRepository $applicationRepository) {
>> 		$this->applicationRepository = $applicationRepository;
>> 	}
>>
>>
>> 	/**
>> 	 * ApplicantRepository does not get injected!
>> 	 * @param Tx_Xxx_Domain_Repository_ApplicantRepository $applicantRepository
>> 	 * @return void
>> 	 */
>> 	public function injectApplicantRepository(Tx_Xxx_Domain_Repository_ApplicantRepository $applicantRepository) {
>> 		$this->applicantRepository = $applicantRepository;
>> 	}
>>
>> }
>>
>>
>> Then I want to call $this->applicantRepository->findByUid() in my initializeAction and I get a Fatal error, call to a member function findByUid() on a non-object.
>>
>> What am I missing?
>>
>> Best regards
>> Alex
>> _______________________________________________
>> TYPO3-project-typo3v4mvc mailing list
>> TYPO3-project-typo3v4mvc at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>



More information about the TYPO3-project-typo3v4mvc mailing list