Before trying to answer your question, let me just add an important piece of information: JSR 330 (@Inject
) was standardized by Guice and Spring projects (announcement from May 2009) and is being reused in JSR 299. This covers basic DI mechanisms in terms of declaring an injection point.
Now, back to the question - with the disclaimer that I have far more experience with Spring than with Guice.
Enterprise capabilities in Weld
- Alternative configuration mechanisms have a very clean design in JSR-299 and allow for configuration mechanisms outside of the Java code (
beans.xml
).
- Events are a very powerful thing and fit nicely with JMS. I just found an Event Bus for Guice, but I cannot say how that compares.
- Portable extensions are an SPI that can be used to integrate with existing technology or wrap legacy code in a clean way.
Advantages / Disadvantages
Note: I will try to add a few items here later, but this answer is already longer than I had expected, sorry.
Weld/CDI
- Standardization: If something is standardized and there is a good implementation, a lot of people will be using it. Example: Built-in scopes in Weld provide a few more scopes than Guice or Spring. All of these can be extended, but application frameworks will rather rely on standard scopes if they are being used by a large community.
- Container support: this is similar to the previous item, but a major argument for adoption. Major open source application servers, such as Glassfish and JBoss 6 provide CDI support (see here).
Guice/Spring
- Actual application: Most of the existing applications will be using Guice/Spring already. Spring/Guice have always built on standards and provided new capabilities where no standards existed or could not be used. If you follow with the respective best-practices, the framework will help you make your application standards-based and clean.
AOP and Interceptors
This is a very heavily discussed topic, and I cannot favor one over the other. Both mechanisms are very powerful but require at least a minimum understanding of the application's architecture. Also have look at Decorators and the previously referenced Events. It is best to go with the right tool, but don't forget that if a developer has to work with one of these mechanisms it is a good thing if he/she understands the concept.
Performance
Unfortunately I could not look into this yet, but there are a few rules I try to follow, especially when using a framework that gives you a lot of functionality without you noticing it:
- Whenever possible, prefer a single wiring step over multiple lookups at runtime.
- If possible, do all the wiring on application initialization.
- Any interception step or AOP proxy adds a few method calls to the stack.