Newbie Alert .
My problem is how to use binding annotation in case when chain of
dependency is not defined with the annotation all the way.
Binding annotations *Excel* and *Word* are used to bind
*ContentHandler* and *IParser* interfaces but not *IState* interface
(see *MyModule*). The dependency looks like this:
ContentHandler -> IState -> IParser
public class ExcelHandler implements ContentHandler {
@Inject
public ExcelHandler(@Excel IParser parser) {
IState = new State(parser);
}
}
public class MyModule extends AbsractModule {
protected void configure() {
bind(ContentHandler.class).annotatedWith(Excel.class).
to(ExcelContentHandler.class);
bind(ContentHandler.class).annotatedWith(Word.class).
to(WordContentHandler.class);
bind(IParser.class).annotatedWith(Excel.class).
to(ExcelParser.class);
bind(IParser.class).annotatedWith(Word.class).
to(WordParser.class);
bind(IState.class).to(State.class);
}
}
I obtain initial instance with injector:
ContentHandler handler =
injector.getInstance(Key.get(ContentHandler.class, Excel.class));
How to use guice to replace explicit constructor?
IState = new State(parser);
--
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.