[TYPO3-mvc] Benefit of DI when referencing to a class (and not to an interface)?

Roland most.wanted at gmx.at
Tue Jun 26 11:17:43 CEST 2012


hi everybody,

is there any pro arguments to create objects through dependency 
injection instead of through 
$this->objectManager->create('Tx_Foo_LogFile', 'arg1', 'arg2') when you 
do reference to an concrete class and not an interface?

i think i guess i understand the benefits (decoupling) of this:

--- quote ---

/**
  * @var Tx_Foo_Service_LoggingServiceInterface
  * @inject
  */
protected $loggingService;

--- /quote ---

but i do not understand the benefit of this compared to the 
$this->objectManager->create() method, except that it is less to type - 
but there is no decoupling, which should be THE advantage of DI, 
shouldn't it?

--- quote ---

/**
  * @var Tx_Foo_Domain_Repository_BarRepository
  * @inject
  */
protected $barRepository;

--- /quote ---

are there any arguments why you should use dependency injection in the 
last mentioned example? are there arguments against it?

kind regards

roland


More information about the TYPO3-project-typo3v4mvc mailing list