【发布时间】:2015-08-28 10:09:26
【问题描述】:
我正在尝试在 Guice 的帮助下注入 Strings 的 ArrayList。我想显示一个带有许多 RadioButtons 的面板(例如),用户可以在其中选择一些服务来激活。
一旦选择,我想获取所选服务的所有名称并将它们添加到列表中,并将此列表注入负责创建服务的经理。这是一个例子:
public class UIProviderModule extends ProviderServiceModule {
private ArrayList<String> requestedServices;
public UIProviderModule(ArrayList<String> requestedServices) {
this.requestedServices = requestedServices;
}
@Override
protected void configure() {
bindConstant().annotatedWith(Names.named(Constants.REQ_SERVICES)).to(requestedServices);
bind(IParser.class).to(UIParser.class);
super.configure();
}
}
我看过很多关于Multibindings 和Providers 的帖子,但我不明白这对我有什么帮助。我只想检索名称,因为我不使用必须绑定到接口的类。我错过了什么吗?
注意:我知道这可能不是使用 Guice 的好方法,因为我将列表绑定到 Module。
【问题讨论】:
标签: java arraylist guice inject