Package com.github.alex1304.rdi.config
Class ServiceDescriptor.Builder
- java.lang.Object
-
- com.github.alex1304.rdi.config.ServiceDescriptor.Builder
-
- Enclosing class:
- ServiceDescriptor
public static class ServiceDescriptor.Builder extends Object
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ServiceDescriptor.Builder
addSetterMethod(String name, Injectable param)
Adds a setter method that is capable of injecting an additional dependency after instantiation.ServiceDescriptor.Builder
addSetterMethod(String name, Injectable param, Class<?> returnType)
Adds a setter method that is capable of injecting an additional dependency after instantiation.ServiceDescriptor
build()
Builds the service descriptor.ServiceDescriptor.Builder
setConcreteType(Class<?> concreteType)
Sets the concrete type of the service to instantiate.ServiceDescriptor.Builder
setFactoryMethod(Function<Class<?>,? extends FactoryMethod> factoryMethod)
Sets the factory method that will instantiate the service, with the potential dependencies to inject.ServiceDescriptor.Builder
setSingleton(boolean isSingleton)
Sets whether to configure the service as singleton.
-
-
-
Method Detail
-
setSingleton
public ServiceDescriptor.Builder setSingleton(boolean isSingleton)
Sets whether to configure the service as singleton. If true, the service will only be instantiated once and all other services depending on it will share the same instance. Defaults totrue
.- Parameters:
isSingleton
- true if singleton, false if not- Returns:
- this builder
-
setConcreteType
public ServiceDescriptor.Builder setConcreteType(@Nullable Class<?> concreteType)
Sets the concrete type of the service to instantiate. It is useful when theServiceReference
is an interface or an abstract type, it allows to specify which implementation to use.- Parameters:
concreteType
- the concrete type to set- Returns:
- this builder
- Throws:
IllegalArgumentException
- if concreteType is not a subtype of the service class
-
setFactoryMethod
public ServiceDescriptor.Builder setFactoryMethod(@Nullable Function<Class<?>,? extends FactoryMethod> factoryMethod)
Sets the factory method that will instantiate the service, with the potential dependencies to inject. Defaults to a constructor with no arguments (FactoryMethod.constructor()
)- Parameters:
factoryMethod
- the factory method to set. The appropriateFunction
can be obtained by using one of the static methods of theFactoryMethod
interface.- Returns:
- this builder
-
addSetterMethod
public ServiceDescriptor.Builder addSetterMethod(String name, Injectable param)
Adds a setter method that is capable of injecting an additional dependency after instantiation.This method may be called multiple times for the same setter. This is useful if your setter actually represents a
add
operation.This assumes that the setter has a
void
return type. If it is not the case, useaddSetterMethod(String, Injectable, Class)
instead to specify a return type for the setter method.- Parameters:
name
- the setter nameparam
- the injectable parameter describing the dependency to inject in the setter- Returns:
- this builder
-
addSetterMethod
public ServiceDescriptor.Builder addSetterMethod(String name, Injectable param, Class<?> returnType)
Adds a setter method that is capable of injecting an additional dependency after instantiation.This method may be called multiple times for the same setter. This is useful if your setter actually represents a
add
operation.This overload allows you to specify a return type for the setter method. In most cases it will be
void
, if that's the case you may preferaddSetterMethod(String, Injectable)
with makes this assumption.- Parameters:
name
- the setter nameparam
- the injectable parameter describing the dependency to inject in the setterreturnType
- the return type of the setter method- Returns:
- this builder
-
build
public ServiceDescriptor build()
Builds the service descriptor.- Returns:
- a newly built
ServiceDescriptor
- Throws:
RdiException
- if one of the injection methods cannot be found in the target class or are not public
-
-