The most important feature of CDI, contrary to Guice, is that it is a standard part of Java EE 6.
The value of this should not be underestimated, since it means that CDI is the DI standard that you should use when coding web applications.
While I looked back at technology to be able to determine how we could have a standard core distribution — suitably prepared — where we could add additional modules as we saw fit, which could override existing functionality without having to change core modules, that is, add an additional jar, and the function is automatically activated.
It turned out that the best way to do this for the code base used in both desktop and web applications is to use JSR-330 annotations for our code, and then use either CDI or Guice (SVN, coming soon in 3.0) as engine.
After several projects, I found it best to use the Guice configuration instead of the opaque magic happening in Weld. In addition, I found that the way to do what we want, as described above using Weld, I should mark the class in the optional jar as @Alternative, and then mention in beans.xml that I want the alternate class to be forced ( and that is not reliable against refactoring).
But overall, the JSR-330 allows us to do something that was very tiring and fragile before (because new so tightly bound), and this is a great win. I can highly recommend finding a DI if you have such a need.
Thorbjørn Ravn Andersen Dec 20 '10 at 19:02 2010-12-20 19:02
source share