Interface ComponentRegistry

All Superinterfaces:
DescribableComponent
All Known Implementing Classes:
DefaultComponentRegistry, SpringComponentRegistry

public interface ComponentRegistry extends DescribableComponent
The starting point when configuring any Axon Framework application.

Provides utilities to register components, decorators of these components, check if a component exists, register enhancers for the entire configurer, register modules, and register component factories.

Since:
5.0.0
Author:
Allard Buijze, Steven van Beelen
  • Method Details

    • registerComponent

      default <C> ComponentRegistry registerComponent(@Nonnull Class<C> type, @Nonnull ComponentBuilder<C> builder)
      Registers a Component that should be made available to other components or modules in the Configuration that this Configurer will result in.

      The given builder function gets the configuration as input, and is expected to provide the component as output. The component will be registered under an Component.Identifier based on the given type.

      Type Parameters:
      C - The type of component the builder builds.
      Parameters:
      type - The declared type of the component to build, typically an interface.
      builder - The builder building the component.
      Returns:
      The current instance of the Configurer for a fluent API.
      Throws:
      ComponentOverrideException - If the override policy is set to OverridePolicy.REJECT and a component with the same type is already defined.
    • registerComponent

      default <C> ComponentRegistry registerComponent(@Nonnull Class<C> type, @Nullable String name, @Nonnull ComponentBuilder<? extends C> builder)
      Registers a Component that should be made available to other components or modules in the Configuration that this Configurer will result in.

      The given builder function gets the configuration as input, and is expected to provide the component as output. The component will be registered under an Component.Identifier based on the given type and name combination.

      Type Parameters:
      C - The type of component the builder builds.
      Parameters:
      type - The declared type of the component to build, typically an interface.
      name - The name of the component to build. Use null when there is no name or use registerComponent(Class, ComponentBuilder) instead.
      builder - The builder building the component.
      Returns:
      The current instance of the Configurer for a fluent API.
      Throws:
      ComponentOverrideException - If the override policy is set to OverridePolicy.REJECT and a component with the same type and name is already defined.
    • registerComponent

      <C> ComponentRegistry registerComponent(@Nonnull ComponentDefinition<? extends C> definition)
      Registers a Component based on the given definition.
      Type Parameters:
      C - The declared type of the component.
      Parameters:
      definition - The definition of the component to register.
      Returns:
      The current instance of the Configurer for a fluent API.
      Throws:
      ComponentOverrideException - If the override policy is set to OverridePolicy.REJECT and a component with the same type and name is already defined.
    • registerDecorator

      default <C, D extends C> ComponentRegistry registerDecorator(@Nonnull Class<C> type, int order, @Nonnull ComponentDecorator<C,D> decorator)
      Registers a Component decorator that will act on all registered components of the given type, regardless of component name.

      Decorators are invoked based on the given order. Decorators with a lower order will be executed before those with a higher one. If decorators depend on the result of another decorator, their order must be strictly higher than the one they depend on.

      The order in which components are decorated by decorators with the same order is undefined.

      Type Parameters:
      C - The type of component the decorator decorates.
      D - The type of component the decorator returns.
      Parameters:
      type - The declared type of the component to decorate, typically an interface.
      order - The order of the given decorator among other decorators.
      decorator - The decoration function for a component of type C.
      Returns:
      The current instance of the Configurer for a fluent API.
    • registerDecorator

      default <C, D extends C> ComponentRegistry registerDecorator(@Nonnull Class<C> type, @Nonnull String name, int order, @Nonnull ComponentDecorator<C,D> decorator)
      Registers a decorator that will act on registered components of the given type and name combination.

      Decorators are invoked based on the given order. Decorators with a lowe order will be executed before those with a higher one. If decorators depend on the result of another decorator, their order must be strictly higher than the one they depend on.

      The order in which components are decorated by decorators with the same order is undefined.

      Type Parameters:
      C - The type of component the decorator decorates.
      D - The type of component the decorator returns.
      Parameters:
      type - The declared type of the component to decorate, typically an interface.
      name - The name of the component to decorate.
      order - The order of the given decorator among other decorators.
      decorator - The decoration function for a component of type C.
      Returns:
      The current instance of the Configurer for a fluent API.
    • registerDecorator

      <C> ComponentRegistry registerDecorator(@Nonnull DecoratorDefinition<C,? extends C> definition)
      Registers a decorator based on the given definition.
      Type Parameters:
      C - The declared type of the component(s) to decorate.
      Parameters:
      definition - The definition of the decorator to apply to components.
      Returns:
      The current instance of the Configurer for a fluent API.
      See Also:
    • hasComponent

      default boolean hasComponent(@Nonnull Class<?> type)
      Check whether there is a Component registered with this Configurer for the given type.
      Parameters:
      type - The type of the Component to check if it exists, typically an interface.
      Returns:
      true when there is a Component registered under the given type, false otherwise.
    • hasComponent

      default boolean hasComponent(@Nonnull Class<?> type, @Nonnull SearchScope searchScope)
      Check whether there is a Component registered with this Configurer for the given type.

      The given searchScope is used to define if the search only checks the current registry, only checks all ancestors, or checks both the current registry and all ancestors.

      Parameters:
      type - The type of the Component to check if it exists, typically an interface.
      searchScope - The enumeration defining the search scope used to check if this registry has a Component.
      Returns:
      true when there is a Component registered under the given type, false otherwise.
    • hasComponent

      default boolean hasComponent(@Nonnull Class<?> type, @Nullable String name)
      Check whether there is a Component registered with this Configurer for the given type and name combination.
      Parameters:
      type - The type of the Component to check if it exists, typically an interface.
      name - The name of the Component to check if it exists. Use null when there is no name or use hasComponent(Class) instead.
      Returns:
      true when there is a Component registered under the given type and name combination, false otherwise.
    • hasComponent

      boolean hasComponent(@Nonnull Class<?> type, @Nullable String name, @Nonnull SearchScope searchScope)
      Check whether there is a Component registered with this Configurer for the given type and name combination.

      The given searchScope is used to define if the search only checks the current registry, only checks all ancestors, or checks both the current registry and all ancestors.

      Parameters:
      type - The type of the Component to check if it exists, typically an interface.
      name - The name of the Component to check if it exists. Use null when there is no name or use hasComponent(Class) instead.
      searchScope - The enumeration defining the search scope used to check if this registry has a Component.
      Returns:
      true when there is a Component registered under the given type and name combination, false otherwise.
    • registerIfNotPresent

      default <C> ComponentRegistry registerIfNotPresent(@Nonnull Class<C> type, @Nonnull ComponentBuilder<C> builder)
      Registers a Component only if there is none yet for the given type.

      The given builder function gets the configuration as input, and is expected to provide the component as output. The component will be registered under an Component.Identifier based on the given type.

      Type Parameters:
      C - The type of component the builder builds.
      Parameters:
      type - The declared type of the component to build, typically an interface.
      builder - The builder building the component.
      Returns:
      The current instance of the Configurer for a fluent API.
    • registerIfNotPresent

      default <C> ComponentRegistry registerIfNotPresent(@Nonnull Class<C> type, @Nonnull ComponentBuilder<C> builder, @Nonnull SearchScope searchScope)
      Registers a Component only if there is none yet for the given type.

      The given builder function gets the configuration as input, and is expected to provide the component as output. The component will be registered under an Component.Identifier based on the given type.

      The given searchScope is used to define if the search only checks the current registry, only checks all ancestors, or checks both the current registry and all ancestors.

      Type Parameters:
      C - The type of component the builder builds.
      Parameters:
      type - The declared type of the component to build, typically an interface.
      builder - The builder building the component.
      searchScope - The enumeration defining the search scope used to check if this registry has a Component.
      Returns:
      The current instance of the Configurer for a fluent API.
    • registerIfNotPresent

      default <C> ComponentRegistry registerIfNotPresent(@Nonnull Class<C> type, @Nullable String name, @Nonnull ComponentBuilder<C> builder)
      Registers a Component only if there is none yet for the given type and name combination.

      The given builder function gets the configuration as input, and is expected to provide the component as output. The component will be registered under an Component.Identifier based on the given type.

      Type Parameters:
      C - The type of component the builder builds.
      Parameters:
      type - The declared type of the component to build (typically an interface) if it has not been registered yet.
      name - The name of the component to build if it has not been registered yet.
      builder - The builder building the component.
      Returns:
      The current instance of the Configurer for a fluent API.
    • registerIfNotPresent

      default <C> ComponentRegistry registerIfNotPresent(@Nonnull Class<C> type, @Nullable String name, @Nonnull ComponentBuilder<C> builder, @Nonnull SearchScope searchScope)
      Registers a Component only if there is none yet for the given type and name combination.

      The given builder function gets the configuration as input, and is expected to provide the component as output. The component will be registered under an Component.Identifier based on the given type.

      The given searchScope is used to define if the search only checks the current registry, only checks all ancestors, or checks both the current registry and all ancestors.

      Type Parameters:
      C - The type of component the builder builds.
      Parameters:
      type - The declared type of the component to build (typically an interface) if it has not been registered yet.
      name - The name of the component to build if it has not been registered yet.
      builder - The builder building the component.
      searchScope - The enumeration defining the search scope used to check if this registry has a Component.
      Returns:
      The current instance of the Configurer for a fluent API.
    • registerIfNotPresent

      default <C> ComponentRegistry registerIfNotPresent(@Nonnull ComponentDefinition<C> definition)
      Registers a Component based on the given definition only if there is none yet for the definition's raw type and name combination.
      Type Parameters:
      C - The declared type of the component.
      Parameters:
      definition - The definition of the component to register.
      Returns:
      The current instance of the Configurer for a fluent API.
    • registerIfNotPresent

      default <C> ComponentRegistry registerIfNotPresent(@Nonnull ComponentDefinition<C> definition, SearchScope searchScope)
      Registers a Component based on the given definition only if there is none yet for the definition's raw type and name combination.

      The given searchScope is used to define if the search only checks the current registry, only checks all ancestors, or checks both the current registry and all ancestors.

      Type Parameters:
      C - The declared type of the component.
      Parameters:
      definition - The definition of the component to register.
      searchScope - The enumeration defining the search scope used to check if this registry has a Component.
      Returns:
      The current instance of the Configurer for a fluent API.
    • registerEnhancer

      ComponentRegistry registerEnhancer(@Nonnull ConfigurationEnhancer enhancer)
      Registers an ConfigurationEnhancer with this ComponentRegistry.

      An enhancer is able to invoke any of the methods on this ComponentRegistry, allowing it to add (sensible) defaults, decorate components, or replace components entirely.

      An enhancer's ConfigurationEnhancer.enhance(ComponentRegistry) method is invoked during the initialization phase when all components have been defined. This is right before the ComponentRegistry creates its Configuration.

      When multiple enhancers have been provided, their ConfigurationEnhancer.order() dictates the enhancement order. For enhancer with the same order, the order of execution is undefined.

      Parameters:
      enhancer - The configuration enhancer to enhance ComponentRegistry during ApplicationConfigurer.build().
      Returns:
      The current instance of the Configurer for a fluent API.
    • registerModule

      ComponentRegistry registerModule(@Nonnull Module module)
      Registers a Module with this registry.

      Note that a Module is able to access the components defined in this ComponentRegistry upon construction, but not vice versa. As such, the Module maintains encapsulation.

      Parameters:
      module - The module builder function to register.
      Returns:
      The current instance of the ComponentRegistry for a fluent API.
      Throws:
      ComponentOverrideException - If a module with the same name already exists.
    • registerFactory

      <C> ComponentRegistry registerFactory(@Nonnull ComponentFactory<C> factory)
      Registers a ComponentFactory with this registry.

      If the Configuration that will contain this registry does not have a component for a given Class and name combination, it will consult all registered component factories. Only if a given factory can produce the requested type will ComponentFactory.construct(String, Configuration) be invoked. When the factory decides to construct a new component, it will be stored in the Configuration for future reference to ensure it's not constructed again.

      Type Parameters:
      C - The component type constructed by the given factory.
      Parameters:
      factory - The component factory to register.
      Returns:
      The current instance of the ComponentRegistry for a fluent API.
    • setOverridePolicy

      ComponentRegistry setOverridePolicy(@Nonnull OverridePolicy overridePolicy)
      Sets the OverridePolicy for this ComponentRegistry.

      This policy dictates what should happen when components are registered with an identifier for which another component is already present.

      Parameters:
      overridePolicy - The override policy for components defined in this registry.
      Returns:
      The current instance of the Configurer for a fluent API.
    • disableEnhancerScanning

      ComponentRegistry disableEnhancerScanning()
      Completely disables scanning for enhancers on the classpath through the ServiceLoader mechanism. Note that this may lead to missing framework functionality. It is recommended to disable specific enhancers through disableEnhancer(Class) instead. Does not affect enhancers that are registered through the registerEnhancer(ConfigurationEnhancer) method.
      Returns:
      The current instance of the Configurer for a fluent API.
    • disableEnhancer

      ComponentRegistry disableEnhancer(Class<? extends ConfigurationEnhancer> enhancerClass)
      Disables the given ConfigurationEnhancer class from executing during the configuration initialization phase. This affects both enhancers registered through the ServiceLoader mechanism and those registered programmatically via registerEnhancer(ConfigurationEnhancer).

      Only specific classes can be disabled, and class hierarchies are not taken into account. If the enhancer has already been invoked when this method is called, disabling will have no effect and a warning will be logged.

      This method is typically called from within another enhancer's ConfigurationEnhancer.enhance(ComponentRegistry) method to prevent subsequent enhancers from executing.

      Parameters:
      enhancerClass - The class of the enhancer to disable.
      Returns:
      The current instance of the Configurer for a fluent API.
    • disableEnhancer

      ComponentRegistry disableEnhancer(@Nonnull String fullyQualifiedClassName)
      Disables the given ConfigurationEnhancer class from executing during the configuration initialization phase. This affects both enhancers registered through the ServiceLoader mechanism and those registered programmatically via registerEnhancer(ConfigurationEnhancer).

      Only specific classes can be disabled, and class hierarchies are not taken into account. If the enhancer has already been invoked when this method is called, disabling will have no effect and a warning will be logged.

      This method is typically called from within another enhancer's ConfigurationEnhancer.enhance(ComponentRegistry) method to prevent subsequent enhancers from executing.

      If the class cannot be found on the classpath, a warning will be logged and the call will have no effect.

      Parameters:
      fullyQualifiedClassName - The fully qualified class name of the enhancer to disable.
      Returns:
      The current instance of the Configurer for a fluent API.