[TYPO3-50-general] Upcoming commit: Big change in the component manager

Robert Lemke robert at typo3.org
Tue Jul 22 09:37:53 CEST 2008

Hi folks,

there's a bit commit I currently working on which contains an  
important change in the component manager.

The point is this: As you know, the best way to get instances of  
_Singleton_ components is using
Dependency Injection - either constructor or setter injection. That's  
a great way to conveniently
get an instance of the desired component and still keep your class  
decoupled from the framework.

However, you sometimes need prototypes too. For example would you like  
to create a new Comment object
in your controller once a blog visitor wants to comment a blog entry.  
For these cases we have two options:

   a) call the component manager's getComponent() method
   b) use method injection by writing an abstract factory method

Since the last T3DD I have been thinking a lot about option b). I  
won't go into details here but the
result was that it has too many disadvantages, so I dropped the idea.

Option a) is generally okay, but the problem is that now many many  
classes actually need a reference
to the component manager. If you want to test such a class you'll want  
to mock the component manager
which is at times a bit difficult because it has some many methods.

Therefore I decided to extract the getComponent() method from the  
component manager and put it into
its own class, the Component Factory. The average class will, in the  
future, only need the Component
Factory and doesn't care about the advanced functions of the Component  
Manager. And the factory will
only contain the getComponent() method - which is extremely easy to  

Last night I started refactoring all packages of the TYPO3 v5  
distribution and I'll continue this
morning. At some point I will commit the changes and then all code  
which was not part of the distribution
will need to be checked. So, what you'll need to do is _manually_  
looking at each place where you
refer to the Component Manager and see if you really need the  
Component Manager's functions or only
the getComponent() method and inject the Factory in the latter case.

Finally let me tell you how glad I am that we have so many unit tests.  
Otherwise these kinds of
refactoring would hardly be possible ...


More information about the TYPO3-project-5_0-general mailing list