Convert Utility classes to Services for Dependency Injection #178
Description
As a follow-up to #176, I suggest to not only rename Utility classes but also to convert them to stateless services which we can inject to objects which actually need them.
The big advantage is that we can mock these services for Unit Testing. As long as we can't mock them, the unit of code we test is actually not a unit of the code but close to all code in some cases. Plus, do we end up testing a lot of code from the core in our test suite. I'm not talking of class testing (which I also consider to be attractive), but we should get closer to an object model which allows class testing. Plus, should we have an opportunity to test code whithout having to run it against the DBMS.
While performing the refactoring of the object model of our Ajax classes, I already started using Services for Dependency Injection using the corresponding namespace DependencyInjection
and Dao
for new classes, but I named them with suffix Utility
for consistency.
DI by TYPO3 is still to come (there's only extbase DI), but as long as we don't use it we can still pseudo-inject dependencies to controllers using init functions. This is not nice for the moment, but it should prepare for easy refactoring for real DI (I'm referring to objects which are not supposed to have access to the object container).
Comments on this issue are welcome.