Skip to content

Commit

Permalink
Add Bind#assignLazyInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
P3ridot committed Sep 2, 2024
1 parent 56c174b commit 619e11d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions di/src/main/java/org/panda_lang/utilities/inject/Bind.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public interface Bind<A extends Annotation> extends Comparable<Bind<A>> {
*/
void assignThrowingInstance(ThrowingSupplier<?, ? extends Exception> valueSupplier);

/**
* Assign lazy instance to the bind, that will be initialized on the first call and cached
*
* @param valueSupplier the supplier to assign
*/
void assignLazyInstance(Supplier<?> valueSupplier);

/**
* Assign custom handler to the bind
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.panda_lang.utilities.inject;

import panda.std.Lazy;
import panda.std.function.ThrowingSupplier;
import panda.std.function.ThrowingTriFunction;
import panda.std.function.TriFunction;
Expand Down Expand Up @@ -61,6 +62,11 @@ public void assignThrowingInstance(ThrowingSupplier<?, ? extends Exception> valu
with(new StaticBindValue<>(valueSupplier));
}

@Override
public void assignLazyInstance(Supplier<?> valueSupplier) {
assignInstance(new Lazy<>(valueSupplier));
}

@Override
public void assignHandler(TriFunction<Property, A, Object[], ?> handler) {
with(new HandledBindValue<>(handler));
Expand Down

0 comments on commit 619e11d

Please sign in to comment.