Skip to content

Commit b4258f0

Browse files
committed
Fix Lazy Priority Generation
It seems that the `asPrimary` code was not getting generated
1 parent f919131 commit b4258f0

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,18 @@ void buildRegister(Append writer) {
367367
writer.append("var $bean = ");
368368
}
369369
writer.append("builder.");
370+
writePriority(writer);
371+
writer.append("register(bean);").eol();
372+
}
373+
374+
public void writePriority(Append writer) {
370375
if (primary) {
371376
writer.append("asPrimary().");
372377
} else if (secondary) {
373378
writer.append("asSecondary().");
374379
} else if (priority != null) {
375380
writer.append("asPriority(%s).", priority);
376381
}
377-
writer.append("register(bean);").eol();
378382
}
379383

380384
void addLifecycleCallbacks(Append writer, String indent) {
@@ -599,17 +603,15 @@ String shortName() {
599603
String packageName() {
600604
if (importedComponent) {
601605
return beanPackageName() + ".di";
602-
} else {
603-
return beanPackageName();
604606
}
607+
return beanPackageName();
605608
}
606609

607610
private String beanPackageName() {
608611
if (beanType.getNestingKind().isNested()) {
609612
return Util.nestedPackageOf(beanQualifiedName());
610-
} else {
611-
return ProcessorUtils.packageOf(beanQualifiedName());
612613
}
614+
return ProcessorUtils.packageOf(beanQualifiedName());
613615
}
614616

615617
private String beanQualifiedName() {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ private void writeAddFor(MethodReader constructor) {
178178
indent += " ";
179179

180180
final String registerProvider;
181+
181182
if (beanReader.proxyLazy()) {
182183
registerProvider = "registerLazy";
183184
} else if (beanReader.lazy()) {
@@ -186,7 +187,9 @@ private void writeAddFor(MethodReader constructor) {
186187
registerProvider = "asPrototype().registerProvider";
187188
}
188189

189-
writer.append(" builder.%s(() -> {", registerProvider).eol();
190+
writer.append(" builder.");
191+
beanReader.writePriority(writer);
192+
writer.append("%s(() -> {", registerProvider).eol();
190193
}
191194
constructor.startTry(writer);
192195
writeCreateBean(constructor);

inject-generator/src/test/java/io/avaje/inject/generator/models/valid/lazy/LazyBean.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import java.io.IOException;
44

55
import io.avaje.inject.Lazy;
6+
import io.avaje.inject.Primary;
67
import jakarta.inject.Inject;
78
import jakarta.inject.Provider;
89
import jakarta.inject.Singleton;
910

1011
@Lazy
1112
@Singleton
13+
@Primary
1214
public class LazyBean {
1315

1416
Provider<Integer> intProvider;

0 commit comments

Comments
 (0)