[TYPO3-mvc] Dependency Injection not working

Claus Due claus at wildside.dk
Wed Feb 1 10:04:07 CET 2012


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