Package com.github.alex1304.rdi.config
Interface Injectable
-
public interface Injectable
Represents an injectable parameter. You may inject known values as well as references to other services.Although not required, the static methods in this interface are designed for use with an
import static
statement for better code readability.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Optional<ServiceReference<?>>
getReference()
Gets the reference of this injectable parameter, if it represents a reference to another service.Class<?>
getType()
Gets the type of this injectable parameter.default Optional<Object>
getValue()
Gets the value of this injectable parameter, if it represents a provided value.static Injectable
ref(ServiceReference<?> ref)
Creates an injectable parameter which represents a reference to another service.static <T> Injectable
ref(ServiceReference<T> ref, Class<? super T> asSupertype)
Creates an injectable parameter which represents a reference to another service.static Injectable
value(boolean value)
Creates an injectable parameter which represents an already known value.static Injectable
value(byte value)
Creates an injectable parameter which represents an already known value.static Injectable
value(char value)
Creates an injectable parameter which represents an already known value.static Injectable
value(double value)
Creates an injectable parameter which represents an already known value.static Injectable
value(float value)
Creates an injectable parameter which represents an already known value.static Injectable
value(int value)
Creates an injectable parameter which represents an already known value.static Injectable
value(long value)
Creates an injectable parameter which represents an already known value.static Injectable
value(short value)
Creates an injectable parameter which represents an already known value.static <T> Injectable
value(T value, Class<? super T> type)
Creates an injectable parameter which represents an already known value.
-
-
-
Method Detail
-
getType
Class<?> getType()
Gets the type of this injectable parameter.- Returns:
- the type
-
getValue
default Optional<Object> getValue()
Gets the value of this injectable parameter, if it represents a provided value.- Returns:
- the value, if applicable
-
getReference
default Optional<ServiceReference<?>> getReference()
Gets the reference of this injectable parameter, if it represents a reference to another service.- Returns:
- the reference, if applicable
-
ref
static Injectable ref(ServiceReference<?> ref)
Creates an injectable parameter which represents a reference to another service.The type of the reference will be used as the type of the parameter to find the correct injection method. If the service referred to by that reference does not match the type of the method parameter (for example the reference is an implementation class while the service constructor or setter expects the superinterface), you will need to use
ref(ServiceReference, Class)
instead.- Parameters:
ref
- the reference- Returns:
- an injectable parameter
-
ref
static <T> Injectable ref(ServiceReference<T> ref, Class<? super T> asSupertype)
Creates an injectable parameter which represents a reference to another service.This overload is suited if you have a configuration where the reference type is a subtype of the parameter type expected by the injection method.
- Type Parameters:
T
- the generic type of the reference, captured to ensure that the second argument is actually a supertype of it- Parameters:
ref
- the referenceasSupertype
- the supertype of the reference that matches will the target injection method's parameter type- Returns:
- an injectable parameter
-
value
static Injectable value(int value)
Creates an injectable parameter which represents an already known value.- Parameters:
value
- the value to inject- Returns:
- an injectable parameter
-
value
static Injectable value(long value)
Creates an injectable parameter which represents an already known value.- Parameters:
value
- the value to inject- Returns:
- an injectable parameter
-
value
static Injectable value(double value)
Creates an injectable parameter which represents an already known value.- Parameters:
value
- the value to inject- Returns:
- an injectable parameter
-
value
static Injectable value(char value)
Creates an injectable parameter which represents an already known value.- Parameters:
value
- the value to inject- Returns:
- an injectable parameter
-
value
static Injectable value(byte value)
Creates an injectable parameter which represents an already known value.- Parameters:
value
- the value to inject- Returns:
- an injectable parameter
-
value
static Injectable value(short value)
Creates an injectable parameter which represents an already known value.- Parameters:
value
- the value to inject- Returns:
- an injectable parameter
-
value
static Injectable value(float value)
Creates an injectable parameter which represents an already known value.- Parameters:
value
- the value to inject- Returns:
- an injectable parameter
-
value
static Injectable value(boolean value)
Creates an injectable parameter which represents an already known value.- Parameters:
value
- the value to inject- Returns:
- an injectable parameter
-
value
static <T> Injectable value(T value, Class<? super T> type)
Creates an injectable parameter which represents an already known value.- Type Parameters:
T
- the generic type of the object, captured to ensure that the second argument is actually a supertype of it- Parameters:
value
- the value to injecttype
- the type of the value. It may be a super type of the actual runtime type of the value, in a such way that it matches with the injection method's parameter type- Returns:
- an injectable parameter
-
-