On Oct 25, 11:27 pm, dg <[EMAIL PROTECTED]> wrote:
> I could be thinking too 'spring-like' and wiring everything by hand, I
> guess. Thoughts?
This is commonly called the 'robot legs' problem and it's something
we've historically been fairly bad at. But the recently-announced
PrivateModules extension can do the trick:
class RobotLegsModule extends AbstractModule {
@Override protected void configure() {
install(new PrivateModule() {
@Override protected void configurePrivateBindings() {
bind(new TypeLiteral<Iterator<Number>>()
{}).to(MyNumbers.class);
bind(View.class).annotatedWith(Names.named("mine")).to(EvenView.class);
expose(View.class).annotatedWith(Names.named("mine"));
}
});
install(new PrivateModule() {
@Override protected void configurePrivateBindings() {
bind(new TypeLiteral<Iterator<Number>>()
{}).to(YourNumbers.class);
bind(View.class).annotatedWith(Names.named("yours")).to(OddView.class);
expose(View.class).annotatedWith(Names.named("yours"));
}
});
...
}
We install two private submodules. These are allowed to bind the same
types - both bind their own Iterator<Number>. But they expose
different bindings: views with different annotations. The top level
class can now inject them both.
Private modules is a very new feature - it was checked in just last
week! This is a great time to try out the feature and to provide
feedback on how it can be improved.
Cheers,
Jesse
http://publicobject.com/2008/10/just-checked-in-privatemodules.html
http://google.com/search?q=robot+legs+guice
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---