Interface ConfigurableInstanceFactory

All Superinterfaces:
InstanceFactory
All Known Implementing Classes:
DefaultInstanceFactory

public interface ConfigurableInstanceFactory extends InstanceFactory
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 Details

    • getRegisteredScope

      @Nullable Scope getRegisteredScope(Class<? extends Annotation> scopeType)
      Gets the registered Scope strategy for the given scope annotation type if defined or null otherwise.
      Parameters:
      scopeType - scope annotation type
      Returns:
      the registered scope instance for the provided scope type
    • registerScope

      void registerScope(Class<? extends Annotation> scopeType, Scope scope)
      Registers a scope annotation type to the given Scope strategy.
      Parameters:
      scopeType - scope annotation type
      scope - scope strategy to use for the given scope type
    • registerBundle

      void registerBundle(Object bundle)
      Registers a bundle. A bundle is an instance of a class with methods annotated with FactoryType-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

      default void registerBundles(Object... bundles)
      Registers multiple bundles.
      Parameters:
      bundles - bundles to install
      See Also:
    • registerBinding

      <T> void registerBinding(Key<? super T> key, Supplier<T> factory)
      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 binding
      factory - factory for value to bind
    • registerBindingIfAbsent

      <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.
      Type Parameters:
      T - type of value returned by factory
      Parameters:
      key - key for binding
      factory - factory for value to bind
    • removeBinding

      void removeBinding(Key<?> key)
      Removes any existing binding for the provided key.
      Parameters:
      key - key to remove previously registered bindings
    • registerFactoryResolver

      void registerFactoryResolver(FactoryResolver<?> resolver)
      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

      void registerInstancePostProcessor(InstancePostProcessor instancePostProcessor)
      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 their Ordered annotations and falls back to the rules in OrderedComparator. 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

      void setReflectionAgent(ReflectionAgent accessor)
      Sets the ReflectionAgent used for invoking AccessibleObject.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

      void injectMembers(Object instance)
      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

      default void validate(AnnotatedElement element, String name, @Nullable Object value)
      Runs discovered constraint validators for the given annotated element, name, and value.
      Parameters:
      element - source of the value to check for constraint annotations
      name - name to use for error reporting
      value - value to validate
      Throws:
      ConstraintValidationException - if validation fails