Skip to content

Commit 65d9321

Browse files
committed
Add @prototype scope test and b -> beanScope in generated source
1 parent 4011c7a commit 65d9321

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.example.myapp.config;
2+
3+
import io.avaje.inject.BeanScope;
4+
import io.avaje.inject.PostConstruct;
5+
import io.avaje.inject.Prototype;
6+
7+
@Prototype
8+
public class LifeProtoTwo {
9+
10+
public String _state;
11+
12+
@PostConstruct
13+
void post(LifeOne one, BeanScope scope) {
14+
_state = "post|"
15+
+ (one != null ? "one|" : "")
16+
+ (scope != null ? "scope" : "");
17+
}
18+
}

blackbox-test-inject/src/test/java/org/example/myapp/config/PostConstructParametersTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ void factorySecondaryAsProvider() {
1414
var two = testScope.get(LifeTwo.class);
1515
var three = testScope.get(LifeThree.class);
1616
var four = testScope.get(LifeFour.class);
17+
var protoTwo = testScope.get(LifeProtoTwo.class);
1718

1819
assertThat(one._state).isEqualTo("post|scope");
1920
assertThat(two._state).isEqualTo("post|one|scope");
2021
assertThat(three._state).isEqualTo("post|one");
2122
assertThat(four._state).isEqualTo("post|one|two");
23+
assertThat(protoTwo._state).isEqualTo("post|one|scope");
2224
}
2325
}
2426

inject-generator/src/main/java/io/avaje/inject/generator/BeanReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ private void writePostConstruct(Append writer, String indent, MethodReader postC
353353
if (params.isEmpty() || Constants.BEANSCOPE.equals(params.get(0).getFullUType().shortType())) {
354354
writer.append("$bean::%s);", methodName).eol();
355355
} else {
356-
writer.append("b -> $bean.%s(", methodName);
357-
writeLifeCycleGet(writer, params, "b", "b");
356+
writer.append("beanScope -> $bean.%s(", methodName);
357+
writeLifeCycleGet(writer, params, "beanScope", "beanScope");
358358
writer.append(");").eol();
359359
}
360360
}

0 commit comments

Comments
 (0)