Я тоже начинаю Java и IoC. Как сделать вещи:Проблема IoC с множественным связыванием
public class Foo{
//private Bar bar; //Bar is an interface private int var; public Foo(){ } public void setVar(int var){
this.var = var;
} public Bar getBar(){
if(var==1){
return new BarImpl1(); //an implemantation of Bar interface
}
else if(var==2){
return new BarImpl2(); //an implemantation of Bar interface
}
else{
return new BarImpl(); //an implemantation of Bar interface
}
}
}
в примере IoC на примере Guice?
public class Foo{
private Bar bar; //Bar is an interface private int var; @Inject public Foo(Bar bar){
this.bar = bar;
} public void setVar(int var){
this.var = var;
} public Bar getBar(){
return bar; // or what else??
}
}
Как настроить мой инжектор?
@Override
protected void configure() {
bind(Bar.class).to(BarImpl.class);
//and what else??
}
Большое спасибо. Это было именно то, как ты всасывал. Благодаря вам я понял Поставщика и MapBinder наконец :) – kospiotr