Last Friday I went to farewell party of a friend of mine, and on this evening I talked with Alex Kiesel who is one of the
XP framework developers about various things, injection support within the XP framework amongst them. As you might or might not know, both Stubbles and XP are similar in some areas, mostly because the developers share a common mindset about what a framework should provide and how things should be done. This got me into thinking about the injection topic more deeply, as I was convinced that a port of the Stubbles IoC package should be feasible without any large efforts, providing the same features as in Stubbles.
Over the weekend I stopped thinking about it and fired my IDE to just code it. And as it turned out, the port was almost a no-brainer. I got everything to work very quickly, and was able to port the test cases as well, gathering 33 running tests.
Unfortunately there is one feature which the XP port can not provide, which is named injection for more than one argument on constructors or setter methods. This means if you need to have a named injection you require a single setter method for each named injection. This is due to the fact that XP does not provide annotations for method parameters, so the @Named annotation can only be applied to methods and therefore is used for all arguments of such an annotated method.
While the idea of "Stubbles for XP" has been thought more than once in the past and this little experiment shows it is possible, it would still be a long way to go, and the IoC package is just a very small part of it. However, to have room for more experiments of such a kind I named the experiment "Stubbles for XP". If you are interested in the source just have a look at the
subversion repository. If you just want to play around with it you might simply download the
stubbles-for-xp-0.1.1.xar file.
However, there is one more caveat until now: I had to patch lang.XPClass because I found no suitable way to call its newInstance() method with a list of arguments, and I don't wanted to use call_user_func_array(). So if you decide to play with it you need to apply a patch. The patch was developed against 5.8.1-dev, but also successfully tested with 5.7.13, same applies to the port itself.
Update: thanks to a hint from Timm it is now possible to use the 0.1.1 release against XP without applying the aforementioned patch.