Wednesday, February 10, 2010

Guice 2.0 - tasty

I'm finally getting a chance to do some work with Guice 2.0. I don't know if I just couldn't wrap my head around Guice in the past and I've finally "gotten" it, or if Guice 2.0 provides a more approachable API. Either way, I'm finding it great to use.

I've been mildly whiny about Guice in the past, stating that it wasn't completely statically typed (which is true, since it's possible you'll ask for a resource at runtime that isn't available because it wasn't configured). But even with that small limitation, I'm finding Guice 2.0 to be far better than Spring for dependency injection. The code is much smaller, much more type-safe, not XML (a big plus), and much more strongly type-checked.

If you haven't checked out Guice, or if you tried Guice 1.0 but haven't tried out 2.0, you should give 2.0 a serious look.

Now I need to integrate Guice with Jersey (the JAX-RS reference implementation)...

3 comments:

R. Mark Volkmann said...

Here's something I still don't get about Guice. Why is it a good idea to embed dependency selections in the code the has the dependencies. I always thought a major point of dependency injections was to separate them ... like Spring without annotations does.

Brian Gilstrap said...

Mark,

I don't think it's appropriate to embed dependency selections into the code with the dependency. I don't think Guice requires or encourages that (though some lazy examples may be coded that way).

Can you clarify, please?

Anonymous said...

Good post and this mail helped me alot in my college assignement. Gratefulness you on your information.