First Quick Look at CDI (of JEE6)
The good news is that you can have a parameterized constructor (one). The docs (at least the Weld docs) tell us that this allows us to have immutable objects. A builder (a la Bloch‘s from EJ2) would have been better, but this is a great relief from the stupidities of default constructors on every object.
As I push farther into this document, though, I‘m kind of overcome by the thought that Enterprise dev is turning dependency injection into its version of string theory. The purported advantages of DI are that you make explicit the wiring up of components. But DI came in on the XML boom where we had cabinets of interconnects that were nameable and traceable. Ok, argument makes sense: pull the random uses of new out of the code. Also, wire together compound components into bigger units (something language does not deal with exceptionally well because there is no concept of a component in any languages that are out there). So doing bean definitions in XML that had subcomponent wirings explicitly laid out made sense. Problem was, XML became its own nightmare and people decided annotations made more sense. So it‘s ‘ok, let‘s go back into the code,‘ begging the question ‘um, how are we better off than we were when we used to do this in the code?‘
The answer is that we have a container doing work for us, assembling components and then managing their scope.
One thing is for sure, and this is generally a good test of whether we are off in the weeds: if we were starting from scratch, JEE6 and CDI would not be what we would produce. That I‘m sure of. It‘s got all the hallmarks of rutted, grooved warps and whip marks. Of course, because the generals are always fighting the last war, but also because each act of creation is simultaneously the putting to death of some prior genus and the birthing of some supposedly superior species, this is what the various powers have come up with. (Further proof that committees drafted from a few of the cognoscenti does not mean you get some magical incantation involving colored smoke and a visitation. As a matter of fact, apparently the road to CDI was insanely contentious and nasty. Read a Guice Bob rant about what a nightmare it was to work with Gavin King.)
The theater of that in JEE6 is not quite as successful as it was in JEE5. Then, we were getting JPA, which made so much bloody sense, the rest of the train was taken on spec. DI, now that it has gotten its moment in the sun, is starting to look more like a rash than a solution to any immediate problems (other than the DI problems of the prior round).
I was reading a blog on here the other day where some guy was flummoxed because he‘d had an app where he had 10 different versions of the same interface dutifully laid out in his XML file and did not know how to do the same with annotations. I suppressed the urge to suggest starting over. Might be a good piece of advice for the spec guys too. I do believe that CDI is better than continuing on with Spring (now a commercial force) with no standards coverage.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)