Class SimpleInjector<T>
java.lang.Object
ch.tocco.nice2.toolbox.api.inject.SimpleInjector<T>
- All Implemented Interfaces:
Injector<T>
When instantiating, the first constructor where every argument can be found is used, where the order is from
the most parameters to the least.
When initializing, first all setter methods are tried. Again the setters are only invoked if there is a
argument value for every parameter. After this, all fields (which still null) are set if a value can be
found. By default the type of the field/parameter is used to get the value from the
. If so, the
method is invoked.
ValueProvider.
This can be overriden specifying the type using the Resource annotation.
At last the object to initialize is checked for implementing
invalid reference
Initializable
invalid reference
Initializable#afterInitialize()
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final ObjectgetFieldValue(Object target, Field field) voidinitialize(T object, ValueProvider provider) First it usesIntrospectorto invoke all setter methods.protected booleaninjectField(T object, Field field, FieldIterable.FieldIterator iter) Check whether to set a field value.instantiate(ValueProvider provider) Creates a new instance by searching for a ctor that can be matched using values from the specified value provider.protected voidinvokeSetMethod(T owner, ValueProvider provider, PropertyDescriptor pdesc, Object curval, Class<?> beanClass) protected voidinvokeSetter(T owner, ValueProvider provider, BeanInfo info) protected voidsetFields(T object, ValueProvider provider) protected final voidsetFieldValue(Object target, Field field, Object value) toString()
-
Constructor Details
-
SimpleInjector
-
SimpleInjector
public SimpleInjector()
-
-
Method Details
-
instantiate
Description copied from interface:InjectorCreates a new instance by searching for a ctor that can be matched using values from the specified value provider. The best constructor is used, which is the one with the greatest number of arguments that can be retrieved using the specifiedValueProvider.- Specified by:
instantiatein interfaceInjector<T>
-
initialize
First it usesIntrospectorto invoke all setter methods. Then all fields are queried and each one is initialized if it isnull. At last if theobjectimplements, itsinvalid reference
Initializableis called.invalid reference
Initializable#afterInitialize()- Specified by:
initializein interfaceInjector<T>
-
injectField
Check whether to set a field value. This will return true for non-final fields that don't have a value yet and only non-private fields of superclass(es). -
setFields
-
invokeSetter
-
invokeSetMethod
protected void invokeSetMethod(T owner, ValueProvider provider, PropertyDescriptor pdesc, Object curval, Class<?> beanClass) -
getFieldValue
-
setFieldValue
-
toString
-