Interface ConfigurableInstanceFactory
- All Superinterfaces:
InstanceFactory
- All Known Implementing Classes:
DefaultInstanceFactory
Configuration manager for the state of an instance factory. Configurable instance factories can form a
hierarchy by newChildInstanceFactory() creating children factories} to enable inheritance
of bindings, scopes, factory resolvers, instance post-processors, and reflection agents.
-
Method Summary
Modifier and TypeMethodDescription@Nullable Scope
getRegisteredScope
(Class<? extends Annotation> scopeType) Gets the registered Scope strategy for the given scope annotation type if defined ornull
otherwise.void
injectMembers
(Object instance) Injects dependencies into the members of the provided instance.Creates a new child instance factory from this factory which uses bindings from this factory as fallback bindings.newChildInstanceFactory
(Supplier<PropertyEnvironment> environment, Supplier<ClassLoader> loader) Creates a new child instance factory from this factory which uses bindings from this factory as fallback bindings.<T> void
registerBinding
(Key<? super T> key, Supplier<T> factory) Registers a binding between a key and factory.<T> void
registerBindingIfAbsent
(Key<? super T> key, Supplier<T> factory) Registers a binding between a key and factory only if no binding exists for that key.void
registerBundle
(Object bundle) Registers a bundle.default void
registerBundles
(Object... bundles) Registers multiple bundles.void
registerFactoryResolver
(FactoryResolver<?> resolver) Registers a factory resolver.void
registerInstancePostProcessor
(InstancePostProcessor instancePostProcessor) Registers an instance post-processor.void
registerScope
(Class<? extends Annotation> scopeType, Scope scope) Registers a scope annotation type to the given Scope strategy.void
removeBinding
(Key<?> key) Removes any existing binding for the provided key.void
setReflectionAgent
(ReflectionAgent accessor) Sets theReflectionAgent
used for invokingAccessibleObject.setAccessible(boolean)
from an appropriate caller class.default void
validate
(AnnotatedElement element, String name, @Nullable Object value) Runs discovered constraint validators for the given annotated element, name, and value.Methods inherited from interface org.apache.logging.log4j.plugins.di.InstanceFactory
getFactory, getFactory, getFactory, getFactory, getFactory, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getTypeConverter, hasBinding
-
Method Details
-
getRegisteredScope
Gets the registered Scope strategy for the given scope annotation type if defined ornull
otherwise.- Parameters:
scopeType
- scope annotation type- Returns:
- the registered scope instance for the provided scope type
-
registerScope
Registers a scope annotation type to the given Scope strategy.- Parameters:
scopeType
- scope annotation typescope
- scope strategy to use for the given scope type
-
registerBundle
Registers a bundle. A bundle is an instance of a class with methods annotated withFactoryType
-annotated annotations which provide dependency-injected bindings. These bindings are registered based on conditional annotations if present.- Parameters:
bundle
- bundle to install with factory methods for factories
-
registerBundles
Registers multiple bundles.- Parameters:
bundles
- bundles to install- See Also:
-
registerBinding
Registers a binding between a key and factory. This overwrites any existing binding the key may have had.- Type Parameters:
T
- type of value returned by factory- Parameters:
key
- key for bindingfactory
- factory for value to bind
-
registerBindingIfAbsent
Registers a binding between a key and factory only if no binding exists for that key.- Type Parameters:
T
- type of value returned by factory- Parameters:
key
- key for bindingfactory
- factory for value to bind
-
removeBinding
Removes any existing binding for the provided key.- Parameters:
key
- key to remove previously registered bindings
-
registerFactoryResolver
Registers a factory resolver. Factory resolvers are additional strategies for resolving factories for a key using existing bindings or other factory resolvers. These are consulted in the order that they are registered.- Parameters:
resolver
- factory resolver to add to this instance factory
-
registerInstancePostProcessor
Registers an instance post-processor. Instance post-processors provide hooks into the lifecycle of instance initialization. When multiple processors are registered, then they are invoked in the order of theirOrdered
annotations and falls back to the rules inOrderedComparator
. When creating a child instance factory, then the child factory is created with a copy of the current registered processors.- Parameters:
instancePostProcessor
- processor to register
-
newChildInstanceFactory
ConfigurableInstanceFactory newChildInstanceFactory()Creates a new child instance factory from this factory which uses bindings from this factory as fallback bindings.- Returns:
- new child instance factory
-
newChildInstanceFactory
ConfigurableInstanceFactory newChildInstanceFactory(Supplier<PropertyEnvironment> environment, Supplier<ClassLoader> loader) Creates a new child instance factory from this factory which uses bindings from this factory as fallback bindings.- Returns:
- new child instance factory
-
setReflectionAgent
Sets theReflectionAgent
used for invokingAccessibleObject.setAccessible(boolean)
from an appropriate caller class. Customizing this allows for changing the base module that other modules should open themselves to.- Parameters:
accessor
- accessor to use
-
injectMembers
Injects dependencies into the members of the provided instance. Injectable fields are set, then injectable methods are invoked (first those with parameters, then those without parameters).- Parameters:
instance
- instance in which to inject member dependencies
-
validate
Runs discovered constraint validators for the given annotated element, name, and value.- Parameters:
element
- source of the value to check for constraint annotationsname
- name to use for error reportingvalue
- value to validate- Throws:
ConstraintValidationException
- if validation fails
-