[FLOW3-general] DependencyInjection: Best practice
Julian Kleinhans
typo3 at kj187.de
Sat Jan 2 16:10:50 CET 2010
Hiho and a happy new year :-)
i have a question about dependency injection!
There a three ways to inject a dependend object
1) Constructor injection
public function __construct(F3\Test $test) {
$this->test = $test;
}
2) Setter injection
public function setTest(F3\Test $test) {
$this->test = $test;
}
or
public function injectTest(F3\Test $test) {
$this->test = $test;
}
3) Property injection
/**
* @var F3\Test
* @inject
*/
protected $this->test;
What is different between 2 and 3? What is the best way ?
The property injection needs no method and is really short.. so i would
say, use property injection instead setter injection.. or is there any
special reason ?
cheers
julian
--
Julian Kleinhans
Certified TYPO3 Integrator
email: typo3 at kj187.de
web: http://www.typo3-tutorials.org
Xing: http://www.xing.com/profile/Julian_Kleinhans
Twitter: http://twitter.com/kj187
More information about the FLOW3-general
mailing list