Package com.github.alex1304.rdi.config
Interface FactoryMethod
-
public interface FactoryMethod
Represents a method that can create a new instance of a service. It can be either a constructor or a static factory. Since the factory method will be inside the same class as the service itself most of the time,FactoryMethod
instances are created via aFunction
parameterized with the owner class, so that you only need to specify the injectable parameters.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 Modifier and Type Method Description static Function<Class<?>,FactoryMethod>
constructor(Injectable... params)
Creates aFactoryMethod
representing a constructor.static Function<Class<?>,FactoryMethod>
externalStaticFactory(Class<?> owner, String methodName, Class<?> returnType, Injectable... params)
Creates aFactoryMethod
representing a static factory method.List<Injectable>
getInjectableParameters()
reactor.core.publisher.Mono<Object>
invoke(Object... args)
static Function<Class<?>,FactoryMethod>
staticFactory(String methodName, Class<?> returnType, Injectable... params)
Creates aFactoryMethod
representing a static factory method.
-
-
-
Method Detail
-
constructor
static Function<Class<?>,FactoryMethod> constructor(Injectable... params)
Creates aFactoryMethod
representing a constructor. The constructor must be public, and the type of the provided injectables must match strictly the signature of the constructor.- Parameters:
params
- describes what to inject in the constructor parameters- Returns:
- a new
FactoryMethod
- Throws:
RdiException
- if the constructor is not public, does not exist or has a signature that doesn't match with the given injectable parameters.
-
staticFactory
static Function<Class<?>,FactoryMethod> staticFactory(String methodName, Class<?> returnType, Injectable... params)
Creates aFactoryMethod
representing a static factory method. The method must be public, and the name, return type, and type of the provided injectables must match strictly the signature of the method.This assumes that the static factory is located in the same class as the service to instantiate. If it isn't the case, use
externalStaticFactory(Class, String, Class, Injectable...)
instead.- Parameters:
methodName
- the name of the methodreturnType
- the return type of the methodparams
- describes what to inject in the method parameters- Returns:
- a new
FactoryMethod
- Throws:
RdiException
- if the method is not public, does not exist or has a signature that doesn't match with the given injectable parameters.
-
externalStaticFactory
static Function<Class<?>,FactoryMethod> externalStaticFactory(Class<?> owner, String methodName, Class<?> returnType, Injectable... params)
Creates aFactoryMethod
representing a static factory method. The method must be public, and the name, return type, and type of the provided injectables must match strictly the signature of the method.If the static factory method is located in the same class as the service to instantiate, you may prefer using
staticFactory(String, Class, Injectable...)
which doesn't require you to specify the owner.- Parameters:
owner
- the class that owns the target factory methodmethodName
- the name of the methodreturnType
- the return type of the methodparams
- describes what to inject in the method parameters- Returns:
- a new
FactoryMethod
- Throws:
RdiException
- if the method is not public, does not exist or has a signature that doesn't match with the given injectable parameters.
-
getInjectableParameters
List<Injectable> getInjectableParameters()
-
-