【问题标题】:GIN: inject an array of objectsGIN:注入对象数组
【发布时间】:2011-09-09 13:16:42
【问题描述】:

有没有办法注入对象数组或对象集合?

@Inject
private A[] objects

如何在我的 GinModule 中为这种情况创建绑定?

【问题讨论】:

    标签: gwt-gin


    【解决方案1】:

    试试这个:

    public class YourModul extends AbstractGinModule {    
        @Provides
        public List<Integer> getIntegers() {
            final List<Integer> integers = new ArrayList<Integer>();
            integers.add(Integer.valueOf(1));
            integers.add(Integer.valueOf(2));
            integers.add(Integer.valueOf(3));
            return integers;
        }
    }
    

    现在可以照常注入整数列表:

    public class YouGinClass {
    
        @Inject
        private List<Integer> integers;
    
    }
    

    getIntegers() 在每次注入整数列表时都会被调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-16
      • 2011-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多