Class DefaultInstanceFactory
java.lang.Object
org.apache.logging.log4j.plugins.di.DefaultInstanceFactory
- All Implemented Interfaces:
ConfigurableInstanceFactory
,InstanceFactory
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> Supplier<T>
createDefaultFactory
(ResolvableKey<T> resolvableKey) getArgumentFactories
(Key<?> key, List<InjectionPoint<?>> argumentInjectionPoints, DependencyChain dependencyChain) protected <T> Supplier<T>
getArgumentFactory
(InjectionPoint<T> injectionPoint, DependencyChain dependencyChain) <T> Supplier<T>
getFactory
(ResolvableKey<T> resolvableKey) Gets a factory for instances that match the given resolvable key.protected <T> @Nullable T
getInjectableInstance
(ResolvableKey<T> resolvableKey) @Nullable Scope
getRegisteredScope
(Class<? extends Annotation> scopeType) Gets the registered Scope strategy for the given scope annotation type if defined ornull
otherwise.protected Scope
getScopeForMethod
(Method method) protected Scope
getScopeForType
(Class<?> type) boolean
hasBinding
(Key<?> key) Indicates if a binding exists for the provided key.protected <T> void
injectField
(Field field, Object instance) void
injectMembers
(Object instance) Injects dependencies into the members of the provided instance.protected void
injectMembers
(Key<?> key, Object instance, DependencyChain dependencyChain) protected <T> @Nullable T
invokeFactory
(Executable factory, Object... arguments) 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.protected <T> T
postProcessAfterInitialization
(ResolvableKey<T> resolvableKey, T instance) protected <T> T
postProcessBeforeInitialization
(ResolvableKey<T> resolvableKey, T instance) <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.protected <T> void
registerBundleMethod
(Object bundleInstance, Method method) 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.resolveKey
(ResolvableKey<T> resolvableKey) void
setReflectionAgent
(ReflectionAgent accessor) Sets theReflectionAgent
used for invokingAccessibleObject.setAccessible(boolean)
from an appropriate caller class.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.logging.log4j.plugins.di.ConfigurableInstanceFactory
registerBundles, validate
Methods inherited from interface org.apache.logging.log4j.plugins.di.InstanceFactory
getFactory, getFactory, getFactory, getFactory, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getTypeConverter
-
Constructor Details
-
DefaultInstanceFactory
protected DefaultInstanceFactory()
-
-
Method Details
-
getFactory
Description copied from interface:InstanceFactory
Gets a factory for instances that match the given resolvable key.- Specified by:
getFactory
in interfaceInstanceFactory
- Type Parameters:
T
- return type of factory- Parameters:
resolvableKey
- key with alias and dependency chain to look up a factory for- Returns:
- a factory for the given resolvable key
-
resolveKey
-
createDefaultFactory
-
getInjectableInstance
-
postProcessBeforeInitialization
-
postProcessAfterInitialization
-
invokeFactory
-
getArgumentFactories
protected List<Supplier<?>> getArgumentFactories(Key<?> key, List<InjectionPoint<?>> argumentInjectionPoints, DependencyChain dependencyChain) -
getArgumentFactory
protected <T> Supplier<T> getArgumentFactory(InjectionPoint<T> injectionPoint, DependencyChain dependencyChain) -
hasBinding
Description copied from interface:InstanceFactory
Indicates if a binding exists for the provided key.- Specified by:
hasBinding
in interfaceInstanceFactory
-
getRegisteredScope
Description copied from interface:ConfigurableInstanceFactory
Gets the registered Scope strategy for the given scope annotation type if defined ornull
otherwise.- Specified by:
getRegisteredScope
in interfaceConfigurableInstanceFactory
- Parameters:
scopeType
- scope annotation type- Returns:
- the registered scope instance for the provided scope type
-
registerScope
Description copied from interface:ConfigurableInstanceFactory
Registers a scope annotation type to the given Scope strategy.- Specified by:
registerScope
in interfaceConfigurableInstanceFactory
- Parameters:
scopeType
- scope annotation typescope
- scope strategy to use for the given scope type
-
getScopeForType
-
getScopeForMethod
-
registerBundle
Description copied from interface:ConfigurableInstanceFactory
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.- Specified by:
registerBundle
in interfaceConfigurableInstanceFactory
- Parameters:
bundle
- bundle to install with factory methods for factories
-
registerBundleMethod
-
registerBinding
Description copied from interface:ConfigurableInstanceFactory
Registers a binding between a key and factory. This overwrites any existing binding the key may have had.- Specified by:
registerBinding
in interfaceConfigurableInstanceFactory
- Type Parameters:
T
- type of value returned by factory- Parameters:
key
- key for bindingfactory
- factory for value to bind
-
registerBindingIfAbsent
Description copied from interface:ConfigurableInstanceFactory
Registers a binding between a key and factory only if no binding exists for that key.- Specified by:
registerBindingIfAbsent
in interfaceConfigurableInstanceFactory
- Type Parameters:
T
- type of value returned by factory- Parameters:
key
- key for bindingfactory
- factory for value to bind
-
removeBinding
Description copied from interface:ConfigurableInstanceFactory
Removes any existing binding for the provided key.- Specified by:
removeBinding
in interfaceConfigurableInstanceFactory
- Parameters:
key
- key to remove previously registered bindings
-
registerFactoryResolver
Description copied from interface:ConfigurableInstanceFactory
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.- Specified by:
registerFactoryResolver
in interfaceConfigurableInstanceFactory
- Parameters:
resolver
- factory resolver to add to this instance factory
-
registerInstancePostProcessor
Description copied from interface:ConfigurableInstanceFactory
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.- Specified by:
registerInstancePostProcessor
in interfaceConfigurableInstanceFactory
- Parameters:
instancePostProcessor
- processor to register
-
newChildInstanceFactory
Description copied from interface:ConfigurableInstanceFactory
Creates a new child instance factory from this factory which uses bindings from this factory as fallback bindings.- Specified by:
newChildInstanceFactory
in interfaceConfigurableInstanceFactory
- Returns:
- new child instance factory
-
newChildInstanceFactory
public ConfigurableInstanceFactory newChildInstanceFactory(Supplier<PropertyEnvironment> environment, Supplier<ClassLoader> loader) Description copied from interface:ConfigurableInstanceFactory
Creates a new child instance factory from this factory which uses bindings from this factory as fallback bindings.- Specified by:
newChildInstanceFactory
in interfaceConfigurableInstanceFactory
- Returns:
- new child instance factory
-
setReflectionAgent
Description copied from interface:ConfigurableInstanceFactory
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.- Specified by:
setReflectionAgent
in interfaceConfigurableInstanceFactory
- Parameters:
accessor
- accessor to use
-
injectMembers
Description copied from interface:ConfigurableInstanceFactory
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).- Specified by:
injectMembers
in interfaceConfigurableInstanceFactory
- Parameters:
instance
- instance in which to inject member dependencies
-
injectMembers
-
injectField
-