Skip to content

Commit e35865e

Browse files
committed
add switch to disable proxy generation
1 parent f053714 commit e35865e

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

blackbox-test-inject/src/main/java/org/example/myapp/lazy/RandomFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import io.avaje.inject.Factory;
88
import io.avaje.inject.Lazy;
99

10-
@Lazy
10+
@Lazy(useProxy = false)
1111
@Factory
1212
public class RandomFactory {
1313
@Bean

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,12 @@ final class BeanReader {
103103
this.observerMethods = typeReader.observerMethods();
104104
this.importedComponent = importedComponent && constructor != null && constructor.isPublic();
105105
this.delayed = shouldDelay();
106-
this.lazyProxyType = !lazy || delayed ? null : Util.lazyProxy(actualType);
106+
boolean useProxy = lazyPrism != null && lazyPrism.useProxy();
107+
this.lazyProxyType = !lazy || delayed || !useProxy ? null : Util.lazyProxy(actualType);
107108
this.proxyLazy = lazy && lazyProxyType != null;
108-
if (lazy && !proxyLazy) {
109-
if (lazyPrism != null && lazyPrism.enforceProxy()) {
109+
110+
if (lazy && !proxyLazy && useProxy) {
111+
if (useProxy && lazyPrism.enforceProxy()) {
110112
logError(beanType, "Lazy beans must have an additional no-arg constructor");
111113
} else {
112114
logWarn(beanType, "Lazy beans should have an additional no-arg constructor");

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ final class MethodReader {
7575
var lazyPrism = Util.isLazy(element);
7676
lazy = lazyPrism != null;
7777
conditions.readAll(element);
78-
this.lazyProxyType = lazy ? Util.lazyProxy(element) : null;
78+
boolean useProxy = lazyPrism != null && lazyPrism.useProxy();
79+
this.lazyProxyType = !lazy || !useProxy ? null : Util.lazyProxy(element);
7980
this.proxyLazy = lazy && lazyProxyType != null;
80-
if (lazy && !proxyLazy) {
81+
82+
if (lazy && !proxyLazy && useProxy) {
8183
if (lazyPrism.enforceProxy()) {
8284
logError(element, "Lazy return type must be abstract or have a no-arg constructor");
8385
} else {

inject/src/main/java/io/avaje/inject/Lazy.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
@Target({ElementType.METHOD, ElementType.TYPE, ElementType.PACKAGE, ElementType.MODULE})
1919
public @interface Lazy {
2020

21+
/** Determine whether a compile-time proxy will be attempted. */
22+
boolean useProxy() default true;
23+
2124
/**
2225
* Ensures that a compile-time proxy is generated, will fail compilation if missing conditions for
2326
* generation

0 commit comments

Comments
 (0)