1

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?

Axl
  • 4,491
  • 3
  • 16
  • 6

1 Answers1

0

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.

Peter
  • 4,752
  • 2
  • 20
  • 32