Re:Spring Dependency Injection Styles – Why I love Java base...
by FlyingSnake on Monday July 23, 2012 @10:38AM
(#4281180)
How's does it compare to Google Guice? Are there any benifits of using a lightweight DI Engine over Spring?
[ Parent
| on HN ]
Re:Spring Dependency Injection Styles – Why I love Java base...
by sgolestane on Monday July 23, 2012 @12:02PM
(#4281609)
On top of dependency injection out of the box Spring offers a lot more, like: Transaction Management, an MVC framework, JDCB templates, ...
Re:Spring Dependency Injection Styles – Why I love Java base...
by peeters on Monday July 23, 2012 @12:32PM
(#4281796)
The key phrase there being "out of the box". Guice does great transaction management, just pull in guice-persist. It integrates with servlets cleanly, just pull in guice-servlet.
The difference is mainly that Guice tries to be a library and Spring tries to be a framework. I, for one, like knowing that I'm not pulling in "the world" just to get dependency injection.
Guice at its core does one thing, and one thing well: dependency injection (and by extension, AOP). It does dependency injection far better than any Spring version I've used (see: constructor injection).
Re:Spring Dependency Injection Styles – Why I love Java base...
by Radu on Monday July 23, 2012 @03:43PM
(#4282702)
Yes, but sooner or later guice won't be enough and you'll use a framework anyway; then the integration mess begins.
With the configuration in code/profiles in Spring 3.1 I don't see any real-world advantage to using guice.
Re:Spring Dependency Injection Styles – Why I love Java base...
by peeters on Monday July 23, 2012 @05:40PM
(#4283182)
Absolutely not. When core Guice "isn't enough", I just grab one of the many great tools that integrate with Guice (Jersey is one example). My DI tool remains my DI tool, and I use a library that provides bindings for it.
Re:Spring Dependency Injection Styles – Why I love Java base...
by nvarsj on Tuesday July 24, 2012 @12:14AM
(#4284326)
> Are there any benifits of using a lightweight DI Engine over Spring?
Well yeah, several.
You don't have to depend on a huge API (spring-core and everything else needed for spring-di) just to get one piece of functionality.
You can avoid using XML as application logic.
You can avoid singletons-as-default-behavior and mutable beans all over the place.
It will likely be faster.