[TYPO3-mvc] Dependency Injection fails only in models
Bastian Waidelich
bastian at typo3.org
Thu Mar 22 15:10:17 CET 2012
Christian Peters wrote:
> Coming from TYPO3, i was used initiating objects via "new"; which is not
> supported by Extbase.
Right, Extbase can't "hook" into the new keyword (this is possible in
FLOW3 because we have the proxy generation there).
BTW: Elsewhere in TYPO3 you should avoid the new keyword too and use
t3lib_div::makeInstance() instead - otherwise the XCLASS and
t3lib_singleton mechanisms are disabled.
> *One final question: *Does dependency injection work, if I receive Models
> through a Repository?
Yes.
> @Frank: How would you suggest to solve the described problem, if you do
> recommend to not use repositories in models (you have a point there)
In general it is *not* violating MVC or DDD concepts if you have
repositories inside a model (we have that in the Blog example, too). But
it might save you hassle if you can avoid it.
For avoiding duplicate entries - I would probably rather check this in
the controller or, transparently, with object validation.
Best,
--
Bastian
More information about the TYPO3-project-typo3v4mvc
mailing list