The new Guice 2 SPI is ready for your feedback.
The Service Provider Interface exposes Guice
internal models to aid in the development in
tools, extensions, and plugins.
Development Story...
This package was built by unifying two
independently developed APIs: Guice Commands
and the injector SPI.
Guice Commands was written to introspect,
rewrite, and validate modules. If you consider a
module to be your injector's source code, then
commands is kind of like static analysis and
code-rewriting -- stuff you do with a compiler
and AST.
http://publicobject.com/2008/02/guice-commands.html
The Injector API was written to inspect
the bindings of an already-built injector. It
gave access to the bindings, and their
dependency graph. If you consider a module
to be your injector's source code, then the
injector API is kind of like reflection -- stuff
you do at runtime.
Motivation...
The new SPI works with the elements of
both Modules and Injectors. It's intended
to give it's users full access to everything
they might need to know. And for the
Modules SPI, it also gives you the ability
to compose new modules from old ones.
At the same time, I want something that's
fairly small and easy enough to code
against. This code snippet logs a warning
for each static injection in your Modules:
public void warnOfStaticInjections(Module... modules) {
for (Element element : Elements.getElements(modules)) {
element.acceptVisitor(new DefaultElementVisitor<Void>() {
@Override
public Void visitStaticInjectionRequest(StaticInjectionRequest
element) {
logger.warning("Static injection is fragile! Please fix "
+ element.getType().getName() + " at " +
element.getSource());
return null;
}
});
}
}
The SPI leans a lot on the visitor pattern,
which I admit is not for everyone.
Please comment...
Grab the latest Guice snapshot from SVN
and take the new SPI for a spin. I wanna
make sure there's no problems in it before
the 2.0 release.
svn checkout
http://google-guice.googlecode.com/svn/trunk/ google-
guice-read-only
Alternately, running through the Javadocs
might give you a feel for the package:
http://google-guice.googlecode.com/svn/trunk/latest-javadoc/com/google/inject/spi/package-summary.html
Note that the Javadoc still needs some
love -- but if there's ideas or suggestions
you have for the docs that's welcome as
well.
Thanks,
Jesse