开发者

GIN: inject an array of objects

开发者_如何学编程Is there a way to inject an array of objects or collection of objects?

@Inject
private A[] objects

How do I create bindings for this case in my GinModule?


Try this:

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;
    }
}

The list of integers can now be injected as usual:

public class YouGinClass {

    @Inject
    private List<Integer> integers;

}

The getIntegers() is invoked everytime when a list of integer should be injected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜