- java.lang.Object
-
- com.github.zhgzhg.tinydi.dynamic.TinyDynamicDI
-
public class TinyDynamicDI extends java.lang.ObjectHelper utilities for dynamic dependency injection.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTinyDynamicDI.TransparentInvocationHandlerHelper used to associate a @Recordedannotation implementation and an instance of an object not implementing.
-
Constructor Summary
Constructors Constructor Description TinyDynamicDI()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TattachRecordedAnnotation(@NonNull java.util.function.Supplier<java.lang.Object> instanceSupplier, java.lang.Class<?> instanceClass, @NonNull Recorded recorded)Attaches aRecordedinstance to non-annotated object by creating a proxy object around it.static java.lang.Class<?>realClass(@NonNull java.lang.Object instance)Obtains the class behind a proxy object with TinyDI'sTinyDynamicDI.TransparentInvocationHandler.static java.lang.ObjectrealInstance(java.lang.Object instance)Obtains the instance behind a proxy object with TinyDI'sTinyDynamicDI.TransparentInvocationHandler.static ScopeDIscopeOfProxy(java.lang.Object instance)Returns the instantiation scope of a proxied viaattachRecordedAnnotation(java.util.function.Supplier<java.lang.Object>, java.lang.Class<?>, com.github.zhgzhg.tinydi.meta.annotations.Recorded)instance.
-
-
-
Method Detail
-
attachRecordedAnnotation
public static <T> T attachRecordedAnnotation(@NonNull @NonNull java.util.function.Supplier<java.lang.Object> instanceSupplier, java.lang.Class<?> instanceClass, @NonNull @NonNull Recorded recorded)Attaches aRecordedinstance to non-annotated object by creating a proxy object around it. Useful when dynamically injecting more components into an already initialized TinyDI context.- Type Parameters:
T- The type the result to be casted to. It must be an interface.Recordedis a safe choice.- Parameters:
instanceSupplier- The instance supplier whose instance will be bound to the annotation.instanceClass- The type of the instance.recorded- AnRecordedinstance with the specified values. UsuallyRecordedAnnotationcan be used for the purpose.- Returns:
- A proxy instance bounding toInstance, it's implemented interfaces along with the passed record one.
- Throws:
java.lang.IllegalArgumentException- if <T> is not an interfacejava.lang.NullPointerException- if toInstance or record are null
-
realClass
public static java.lang.Class<?> realClass(@NonNull @NonNull java.lang.Object instance)Obtains the class behind a proxy object with TinyDI'sTinyDynamicDI.TransparentInvocationHandler.- Parameters:
instance- The instance to work with.- Returns:
- The class behind the proxy object, or the instance's class if the latter is not a proxy.
- Throws:
java.lang.ClassCastException- if the proxy object's handler is not ofTinyDynamicDI.TransparentInvocationHandlertype.
-
realInstance
public static java.lang.Object realInstance(java.lang.Object instance)
Obtains the instance behind a proxy object with TinyDI'sTinyDynamicDI.TransparentInvocationHandler.- Parameters:
instance- The instance to work with.- Returns:
- The instance behind the proxy object, or the actual instance if the latter is not a proxy.
- Throws:
java.lang.ClassCastException- if the proxy object's handler is not ofTinyDynamicDI.TransparentInvocationHandlertype.
-
scopeOfProxy
public static ScopeDI scopeOfProxy(java.lang.Object instance)
Returns the instantiation scope of a proxied viaattachRecordedAnnotation(java.util.function.Supplier<java.lang.Object>, java.lang.Class<?>, com.github.zhgzhg.tinydi.meta.annotations.Recorded)instance.- Parameters:
instance- The instance to inspect- Returns:
- Nonnull value, or null if the instance is not proxied.
-
-