I was working with GUice some months ago and now when I return to it, I find I have to reread the Guice documentation and examples to understand what I did with my c开发者_运维百科ode.
However, when I look at AspectJ it is all too intuitive. It is an intuitive extension of the Java language. I feel I can sit down and write AspectJ code immediately already.
Therefore, I am tempted to abandon my pursuit of Guice and go with AspectJ. Especially the fact that Spring is generating AspectJ code.
What features of Guice are there above AspectJ that should discourage me from abandoning Guice?
Why wouldn't Google abandon Guice and use AspectJ instead?
Vice Versa, What are the features of AspectJ that would encourage me to abandon Guice, besides the intuitiveness of it?
If I may be allowed to "weave" in a question here, what is precluding Java language from being merged with AspectJ or provide similar "aspects" in a future version of Java?
Note: to trigger happy delete-azillas, I realise this question may be too general - but if I knew what further specifics to ask, then I would not even need to ask but just google/bing for what I know that I don't know. As you can see, my Guice knowledge has degraded so badly that I don't even recognise my own handwriting.
As Peter says, Guice and AspectJ are totally different things. Guice does dependency injection, saving lots of factory writing while making code flexible and easy to test and adding useful things like scopes. It also happens to allow a very simple, easy way of doing AOP via method interception (with programmatic configuration of what methods get intercepted, rather than a DSL). This is effectively just another bonus it provides and not its core goal at all.
As far as why AspectJ isn't merged into Java... I don't feel like many people would want that to happen. AOP is powerful, but in a dangerous way. While it's certainly great for some uses and simplifies code a lot in those cases, if overused it could make it a lot harder to comprehend what happens in a program.
According to me AspectJ and Guice do different things.
Guice injects dependencies and AspectJ deals with crosscutting concerns.
If you use spring then indeed there is less value in using Guice since there is too much overlap and then the symbiosis of Spring/AspectJ is a compelling solution.
I personqlly like guice better for non-spring projects because of its lighter weight.
Spring is built on dependency injection and aspect-oriented programming.
Guice is a dependency injection engine.
AspectJ is an aspect-oriented engine.
See the difference? Guice and AspectJ would be complementary; Spring already has both.
It should be mentioned that Spring supports its own interceptor based AOP, which doesn't require byte code manipulation, in addition to AspectJ.
精彩评论