Package org.panda_lang.utilities.inject
Interface Injector
public interface Injector
-
Method Summary
Modifier and TypeMethodDescriptionduplicate(InjectorController controller) Duplicate (clone) resources<T> ConstructorInjector<T>forConstructor(Class<T> type) Create injector for the given type<T> ConstructorInjector<T>forConstructor(Constructor<T> constructor) Create injector for the given constructor<T> FieldsInjector<T>Create injector for fields (and constructor)<T> FieldsInjector<T>forFields(Constructor<T> constructor) Create injector for fields (and constructor)forGeneratedMethod(Method method) Generate injector for the given methodfork(InjectorController controller) Create a fork of resources.Create injector for the given methodGet resources of injectorvoidinvokeAnnotatedMethods(Class<? extends Annotation> annotation, Object instance, Object... injectorArgs) Invoke methods annotated with the given annotation<T> TinvokeMethod(Method method, @Nullable Object instance, Object... injectorArgs) Invoke the method using Injector<T> TinvokeParameter(Parameter parameter, Object... injectorArgs) Get value that would be used to inject the given parameter<T> TnewInstance(Class<T> type, Object... injectorArgs) Create a new instance of the specified type using Injector<T> TnewInstance(Constructor<T> constructor, Object... injectorArgs) Create a new instance of the specified constructor using Injector<T> TnewInstanceWithFields(Class<T> type, Object... injectorArgs) Create a new instance of the specified type using Injector with support for field injection<T> TnewInstanceWithFields(Constructor<T> constructor, Object... injectorArgs) Create a new instance of the specified constructor using Injector with support for field injection
-
Method Details
-
forConstructor
Create injector for the given type- Type Parameters:
T- type of class- Parameters:
type- the type to process- Returns:
- constructor injector
-
forConstructor
Create injector for the given constructor- Type Parameters:
T- type of class- Parameters:
constructor- the constructor to process- Returns:
- constructor injector
-
forFields
Create injector for fields (and constructor)- Type Parameters:
T- type of class- Parameters:
type- the type to process- Returns:
- fields injector
-
forFields
Create injector for fields (and constructor)- Type Parameters:
T- type of class- Parameters:
constructor- the constructor to process- Returns:
- fields injector
-
newInstance
Create a new instance of the specified type using Injector- Type Parameters:
T- the type- Parameters:
type- the class to instantiate- Returns:
- a new instance
- Throws:
DependencyInjectionException- if anything happened during the injection
-
newInstance
<T> T newInstance(Constructor<T> constructor, Object... injectorArgs) throws DependencyInjectionException Create a new instance of the specified constructor using Injector- Type Parameters:
T- the type- Parameters:
constructor- the constructor to instantiate- Returns:
- a new instance
- Throws:
DependencyInjectionException- if anything happens during the injection
-
newInstanceWithFields
<T> T newInstanceWithFields(Class<T> type, Object... injectorArgs) throws DependencyInjectionException Create a new instance of the specified type using Injector with support for field injection- Type Parameters:
T- type of class- Parameters:
type- the class to instantiate- Returns:
- a new instance
- Throws:
DependencyInjectionException- if anything happens during the injection
-
newInstanceWithFields
<T> T newInstanceWithFields(Constructor<T> constructor, Object... injectorArgs) throws DependencyInjectionException Create a new instance of the specified constructor using Injector with support for field injection- Type Parameters:
T- type of class- Parameters:
constructor- the constructor to instantiate- Returns:
- a new instance
- Throws:
DependencyInjectionException- if anything happens during the injection
-
forMethod
Create injector for the given method- Parameters:
method- the method to process- Returns:
- injector for the given method
-
forGeneratedMethod
Generate injector for the given methodThis method should be used only with di-codegen module or other
MethodInjectorimplementation Otherwise, it will fall back toforMethod(Method)and performance could be degraded- Parameters:
method- the method to process (works only for public properties)- Returns:
- injector for the given method
- Throws:
Exception- if anything happens during the generation of method wrapper
-
invokeMethod
@Nullable <T> T invokeMethod(Method method, @Nullable @Nullable Object instance, Object... injectorArgs) throws DependencyInjectionException Invoke the method using Injector- Type Parameters:
T- the return type- Parameters:
method- the method to invokeinstance- the instance to use (nullable for static context)- Returns:
- the return value
- Throws:
DependencyInjectionException- if anything happens during execution of the method
-
invokeAnnotatedMethods
void invokeAnnotatedMethods(Class<? extends Annotation> annotation, Object instance, Object... injectorArgs) throws DependencyInjectionException Invoke methods annotated with the given annotation- Parameters:
annotation- the annotation to look forinstance- the instance to use- Throws:
DependencyInjectionException- if anything happens during execution of the methods
-
invokeParameter
Get value that would be used to inject the given parameter- Type Parameters:
T- type of expected value- Parameters:
parameter- the parameter for which the value will be returned- Returns:
- the associated binding value
- Throws:
Exception- if anything happens during invocation of the parameter
-
fork
Create a fork of resources. The current resources will be used as a parent of a new instance.- Parameters:
controller- initializer for a new instance of resources- Returns:
- a forked instance of resources
-
duplicate
Duplicate (clone) resources- Parameters:
controller- initializer for a new instance of resources- Returns:
- a duplicated instance of resources
-
getResources
Resources getResources()Get resources of injector- Returns:
- the resources
-