Friday
Jan232009
Guice 1.0 vs 2.0
Friday, January 23, 2009 at 5:42PM The Guice 2.0 contains lots of neat improvements. It removes lots of unnecessary boilerplate and allows to write more compact Guice modules. Here is an example of how a confusing binding can be refactored into a simple provider method.
Example using Guice 1.0:
@Override
protected void configure() {
bind(new TypeLiteral<List<string>>(){})
.annotatedWith(TagsToProcess.class)
.toProvider(TagsProvider.class);
}
The same example using Guice 2.0:
@Provides @TagsToProcess
public List<string> provideTags(@Named("tags") String tags) {
return ImmutableList.of(StringUtil.splitAndTrim(tags, ","));
}

Reader Comments (1)
Yeah, I love the way annotations work with provider methods.