Skip to content

Commit 619e11d

Browse files
committed
Add Bind#assignLazyInstance
1 parent 56c174b commit 619e11d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

di/src/main/java/org/panda_lang/utilities/inject/Bind.java

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public interface Bind<A extends Annotation> extends Comparable<Bind<A>> {
4646
*/
4747
void assignThrowingInstance(ThrowingSupplier<?, ? extends Exception> valueSupplier);
4848

49+
/**
50+
* Assign lazy instance to the bind, that will be initialized on the first call and cached
51+
*
52+
* @param valueSupplier the supplier to assign
53+
*/
54+
void assignLazyInstance(Supplier<?> valueSupplier);
55+
4956
/**
5057
* Assign custom handler to the bind
5158
*

di/src/main/java/org/panda_lang/utilities/inject/DefaultBind.java

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.panda_lang.utilities.inject;
1818

19+
import panda.std.Lazy;
1920
import panda.std.function.ThrowingSupplier;
2021
import panda.std.function.ThrowingTriFunction;
2122
import panda.std.function.TriFunction;
@@ -61,6 +62,11 @@ public void assignThrowingInstance(ThrowingSupplier<?, ? extends Exception> valu
6162
with(new StaticBindValue<>(valueSupplier));
6263
}
6364

65+
@Override
66+
public void assignLazyInstance(Supplier<?> valueSupplier) {
67+
assignInstance(new Lazy<>(valueSupplier));
68+
}
69+
6470
@Override
6571
public void assignHandler(TriFunction<Property, A, Object[], ?> handler) {
6672
with(new HandledBindValue<>(handler));

0 commit comments

Comments
 (0)