[TYPO3-mvc] Dependency Injection not working

Alexander Dick typo3 at dick.at
Wed Feb 1 09:27:34 CET 2012


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


More information about the TYPO3-project-typo3v4mvc mailing list