0

I'm reading the Arquillian Reference Guide which is very well written, however in the chapter that talks about setting up dependency injection I can't find where you actually specify the beans/bindings.

Most of the Arquillian CDI code examples show the use of Java's @Inject annotation. So I'm just wondering, where I define these beans/DI mappings/bindings, and how do I configure Arquillian to use them?

In Spring DI, you specify a bean descriptor, like spring-config.xml. In Guice you implement a Module and define its configure(Binder) method. What does this look like in Arquillian-land when using javax.inject.Inject? Thanks in advance.

IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756

2 Answers2

2

The short answer - there is no need to define bean mappings in CDI, because CDI works with annotations exclusively. You can add extra information in config-files, but this is usually not required.

The long answer is best taken from this excellent introduction into CDI.

Jan Groth
  • 14,039
  • 5
  • 40
  • 55
  • Thanks @jan groth (+1) - So if my Arquillian integration test has a `private @Inject Fruit fruit` field, and I want that `fruit` interface to be injected with an `Apple` instance inside the container, how do I configure that binding? – IAmYourFaja Jun 29 '12 at 16:21
  • `private @Inject Fruit fruit` if there is one implementation of Fruit, `private @Inject @Apple Fruit fruit` if there are more. But you should go through the referenced introduction, that's way too much to explain here... – Jan Groth Jun 29 '12 at 18:12
0

I think you need to use "Alternatives" CDI mechanism

Alternatives are beans whose implementation is specific to a particular client module or deployment scenario.

Tair
  • 3,779
  • 2
  • 20
  • 33
  • This is not how alternatives are intended to work. Using xml for to manage such a common thing would be pretty terrible. Correct answer is @jan groth – Karl Kildén Jul 13 '12 at 12:34
  • Ok, what for then we need alternatives? :) – Tair Jul 13 '12 at 12:39
  • Actually, in context of integration testing with Arquillian, as was mentioned by OP in comment to @jan's answer, I think this is indeed the simplest way of specifying alternative implementation of a bean – Tair Jul 13 '12 at 12:44