[FLOW3-general] DependencyInjection: Best practice
Robert Lemke
robert at typo3.org
Thu Jan 7 10:04:45 CET 2010
Hi Steffen,
Am 06.01.2010 um 18:58 schrieb Steffen Müller:
>> Although there is a little perfomance gain when using 2), it is much more convenient to use 3). However, 2) is more portable than 3) because 3) really relies on the framework to know about @inject annotations. I recommend that you use 3) in all of your applications if the portability aspect is not important in your case. I must admit though that we have the policy to use only setter injection in FLOW3 itself due to speed reasons and some other implications.
>
> Sorry. I didn't get it.
> You propose 3) as more convenient, but for which reasons?
Less typing:
2)
class MyClass {
/**
* @var \F3\FLOW3\Object\FactoryInterface
*/
protected $objectFactory
/**
* Injects the object factory
*
* @param \F3\FLOW3\Object\FactoryInterface $objectFactory
* @return void
*/
public function injectObjectFactory(\F3\FLOW3\Object\FactoryInterface $objectFactory) {
$this->objectFactory = $objectFactory;
}
}
3)
class MyClass {
/**
* @inject
* @var \F3\FLOW3\Object\FactoryInterface
*/
protected $objectFactory
}
Portability and performance might be better in 2)
yes.
Cheers,
robert
More information about the FLOW3-general
mailing list