Class DefaultComponentRegistry

java.lang.Object
org.axonframework.common.configuration.DefaultComponentRegistry
All Implemented Interfaces:
ComponentRegistry, DescribableComponent

public class DefaultComponentRegistry extends Object implements ComponentRegistry
Default implementation of the ComponentRegistry allowing for reuse of Component, ComponentDecorator, ConfigurationEnhancer, and Module registration for the ApplicationConfigurer and Module implementations alike.
Since:
5.0.0
Author:
Allard Buijze, Steven van Beelen
  • Constructor Details

    • DefaultComponentRegistry

      public DefaultComponentRegistry()
  • Method Details

    • create

      Creates a new registry. This will include the provided enhancers, disabled enhancers and decorator definitions except those annotated with RegistrationScope. The enhancerScanning flag is set to false.
      Parameters:
      decoratorDefinitions - The list of decorator definitions to copy.
      enhancers - The list of enhancers to copy.
      disabledEnhancers - The list of disabled enhancer types to copy.
      Returns:
      A new default component registry.
    • registerComponent

      public <C> ComponentRegistry registerComponent(ComponentDefinition<? extends C> definition)
      Description copied from interface: ComponentRegistry
      Registers a Component based on the given definition.
      Specified by:
      registerComponent in interface ComponentRegistry
      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.
    • registerDecorator

      public <C> ComponentRegistry registerDecorator(DecoratorDefinition<C,? extends C> definition)
      Description copied from interface: ComponentRegistry
      Registers a decorator based on the given definition.
      Specified by:
      registerDecorator in interface ComponentRegistry
      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

      public boolean hasComponent(Class<?> type, @Nullable String name, SearchScope searchScope)
      Description copied from interface: ComponentRegistry
      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.

      Specified by:
      hasComponent in interface ComponentRegistry
      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 ComponentRegistry.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.
    • registerEnhancer

      public ComponentRegistry registerEnhancer(ConfigurationEnhancer enhancer)
      Description copied from interface: ComponentRegistry
      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.

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

      public ComponentRegistry registerModule(Module module)
      Description copied from interface: ComponentRegistry
      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.

      Specified by:
      registerModule in interface ComponentRegistry
      Parameters:
      module - The module builder function to register.
      Returns:
      The current instance of the ComponentRegistry for a fluent API.
    • registerFactory

      public <C> ComponentRegistry registerFactory(ComponentFactory<C> factory)
      Description copied from interface: ComponentRegistry
      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.

      Specified by:
      registerFactory in interface ComponentRegistry
      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.
    • build

      public Configuration build(LifecycleRegistry lifecycleRegistry)
      Builds the Configuration from this ComponentRegistry as a root configuration.

      The given lifecycleRegistry is used to register components' lifecycle methods.

      Parameters:
      lifecycleRegistry - The registry where lifecycle handlers are registered.
      Returns:
      A fully initialized configuration exposing all configured components.
    • buildNested

      public Configuration buildNested(Configuration parent, LifecycleRegistry lifecycleRegistry)
      Builds the Configuration from this ComponentRegistry as a nested configuration under the given parent.

      Components registered in the parent are available to components registered in this registry, but not vice versa. The given lifecycleRegistry is used to register components' lifecycle methods.

      Parameters:
      parent - The parent configuration.
      lifecycleRegistry - The registry where lifecycle handlers are registered.
      Returns:
      A fully initialized configuration exposing all configured components.
    • createLocalConfiguration

      @Internal public Configuration createLocalConfiguration(Configuration parent)
      Creates a local configuration, for a given parent and current registry as a component.
      Parameters:
      parent - The parent configuration to serve as parent for the created result.
      Returns:
      A new local configuration with parent referencing to components of the current registry.
    • setOverridePolicy

      public DefaultComponentRegistry setOverridePolicy(OverridePolicy overridePolicy)
      Description copied from interface: ComponentRegistry
      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.

      Specified by:
      setOverridePolicy in interface ComponentRegistry
      Parameters:
      overridePolicy - The override policy for components defined in this registry.
      Returns:
      The current instance of the Configurer for a fluent API.
    • disableEnhancer

      public ComponentRegistry disableEnhancer(String fullyQualifiedClassName)
      Description copied from interface: ComponentRegistry
      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 ComponentRegistry.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.

      Specified by:
      disableEnhancer in interface ComponentRegistry
      Parameters:
      fullyQualifiedClassName - The fully qualified class name of the enhancer to disable.
      Returns:
      The current instance of the Configurer for a fluent API.
    • disableEnhancer

      public DefaultComponentRegistry disableEnhancer(Class<? extends ConfigurationEnhancer> enhancerClass)
      Description copied from interface: ComponentRegistry
      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 ComponentRegistry.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.

      Specified by:
      disableEnhancer in interface ComponentRegistry
      Parameters:
      enhancerClass - The class of the enhancer to disable.
      Returns:
      The current instance of the Configurer for a fluent API.
    • disableEnhancerScanning

      public DefaultComponentRegistry disableEnhancerScanning()
      Description copied from interface: ComponentRegistry
      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 ComponentRegistry.disableEnhancer(Class) instead. Does not affect enhancers that are registered through the ComponentRegistry.registerEnhancer(ConfigurationEnhancer) method.
      Specified by:
      disableEnhancerScanning in interface ComponentRegistry
      Returns:
      The current instance of the Configurer for a fluent API.
    • describeTo

      public void describeTo(ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.

      Best Practices: As a general rule, all relevant fields of a DescribableComponent implementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing the describeTo method, who should focus on providing information that is useful for understanding the component's configuration and state.

      Example implementation:

       public void describeTo(ComponentDescriptor descriptor) {
           descriptor.describeProperty("name", this.name);
           descriptor.describeProperty("enabled", this.enabled);
           descriptor.describeProperty("configuration", this.configuration); // A nested component
           descriptor.describeProperty("handlers", this.eventHandlers);      // A collection
       }
       
      Specified by:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.