Skip to content

Commit 07a5b9d

Browse files
committed
#38 - Support multiple @factory @nAmed beans
1 parent d6f2775 commit 07a5b9d

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<dependency>
5757
<groupId>io.dinject</groupId>
5858
<artifactId>dinject-generator</artifactId>
59-
<version>1.17</version>
59+
<version>1.18-SNAPSHOT</version>
6060
<scope>test</scope>
6161
</dependency>
6262

src/test/java/org/example/coffee/factory/MultipleOtherThings.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ public class MultipleOtherThings {
88

99
private final Otherthing blue;
1010
private final Otherthing red;
11-
// private final Otherthing green;
12-
// private final Otherthing yellow;
11+
private final Otherthing green;
12+
private final Otherthing yellow;
1313

14-
MultipleOtherThings(@Named("blue") Otherthing blue, @Named("red") Otherthing red) {
15-
// , @Named("green") Otherthing green, @Named("yellow") Otherthing yellow) {
14+
MultipleOtherThings(@Named("blue") Otherthing blue, @Named("red") Otherthing red, @Named("green") Otherthing green, @Named("yellow") Otherthing yellow) {
1615
this.blue = blue;
1716
this.red = red;
18-
// this.green = green;
19-
// this.yellow = yellow;
17+
this.green = green;
18+
this.yellow = yellow;
2019
}
2120

2221
public String blue() {
@@ -27,11 +26,11 @@ public String red() {
2726
return red.doOther();
2827
}
2928

30-
// public String green() {
31-
// return green.doOther();
32-
// }
29+
public String green() {
30+
return green.doOther();
31+
}
3332

34-
// public String yellow() {
35-
// return yellow.doOther();
36-
// }
33+
public String yellow() {
34+
return yellow.doOther();
35+
}
3736
}

src/test/java/org/example/coffee/factory/MultipleOtherThingsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public void test() {
1515
final MultipleOtherThings combined = context.getBean(MultipleOtherThings.class);
1616
assertEquals("blue", combined.blue());
1717
assertEquals("red", combined.red());
18-
// assertEquals("green", combined.green());
19-
// assertEquals("yellow", combined.yellow());
18+
assertEquals("green", combined.green());
19+
assertEquals("yellow", combined.yellow());
2020
}
2121
}
2222
}

src/test/java/org/example/coffee/factory/MyFactory.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import io.dinject.Factory;
55
import org.example.coffee.factory.other.Something;
66

7+
import javax.inject.Named;
8+
79
@Factory
810
public class MyFactory {
911

@@ -16,16 +18,16 @@ CFact buildCFact() {
1618
Something buildSomething() {
1719
return new SomeImpl();
1820
}
19-
//
20-
// @Bean
21-
// @Named("green")
22-
// Otherthing greenOther() {
23-
// return () -> "green";
24-
// }
25-
//
26-
// @Bean
27-
// @Named("yellow")
28-
// Otherthing yellowOther() {
29-
// return () -> "yellow";
30-
// }
21+
22+
@Bean
23+
@Named("green")
24+
Otherthing greenOther() {
25+
return () -> "green";
26+
}
27+
28+
@Bean
29+
@Named("yellow")
30+
Otherthing yellowOther() {
31+
return () -> "yellow";
32+
}
3133
}

0 commit comments

Comments
 (0)