[TYPO3-mvc] Using interfaces for dependency injection on domain models

Christian Zenker christian.zenker at 599media.de
Wed Mar 30 09:59:20 CEST 2011


On Tue, 29 Mar 2011 19:57:56 +0200, Thomas "Thasmo" Deinhamer  
<thasmo at gmail.com> wrote:

Hi Thomas.

> Is DI capable of instantiating the correct,
> concrete class, when using interfaces for domain models?

The current official version in TYPO3 4.5 is not, as the domain models are  
not instantiated by the object manager, but a simple "new"-statement.  
There was a bug report in the tracker, and the changes were committed to  
the official repository a few days ago. So it should work if you check out  
the current development version.

>> Is it also recommended or does it make sense to
>> also use interfaces on domain models, so someone
>> could easily exchange models with TypoScript?

My opinion is, that it does not make sense to have an interface for every  
class, just to have an interface. The object manager is capable of  
returning a class instead of another class, too.

I would not create an interface, if I just assume the user would like to  
add a property to the model to extend it. There would be yet another place  
where to do changes if you decide to change something on your model. In  
this case the user could just extend your model.

An interface would be more fitting in my opinion, if it was common to use  
different tables for the same purpose, like fetching information on users  
in tt_address, fe_users, etc. This way you can ensure that you can use the  
same views for every model.

These are just my thoughts and how I would handle it. I hope they help  
somehow.

Christian.


More information about the TYPO3-project-typo3v4mvc mailing list