Interface ComponentRegistry
- All Superinterfaces:
DescribableComponent
- All Known Implementing Classes:
DefaultComponentRegistry,SpringComponentRegistry
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 Summary
Modifier and TypeMethodDescriptiondisableEnhancer(Class<? extends ConfigurationEnhancer> enhancerClass) Disables the givenConfigurationEnhancerclass from executing during the configuration initialization phase.disableEnhancer(String fullyQualifiedClassName) Disables the givenConfigurationEnhancerclass from executing during the configuration initialization phase.Completely disables scanning for enhancers on the classpath through theServiceLoadermechanism.default booleanhasComponent(Class<?> type) default booleanhasComponent(Class<?> type, String name) Check whether there is aComponentregistered with thisConfigurerfor the giventypeandnamecombination.booleanhasComponent(Class<?> type, String name, SearchScope searchScope) Check whether there is aComponentregistered with thisConfigurerfor the giventypeandnamecombination.default booleanhasComponent(Class<?> type, SearchScope searchScope) default <C> ComponentRegistryregisterComponent(Class<C> type, String name, ComponentBuilder<? extends C> builder) Registers aComponentthat should be made available to othercomponentsormodulesin theConfigurationthat thisConfigurerwill result in.default <C> ComponentRegistryregisterComponent(Class<C> type, ComponentBuilder<C> builder) Registers aComponentthat should be made available to othercomponentsormodulesin theConfigurationthat thisConfigurerwill result in.registerComponent(ComponentDefinition<? extends C> definition) Registers aComponentbased on the givendefinition.default <C,D extends C>
ComponentRegistryregisterDecorator(Class<C> type, int order, ComponentDecorator<C, D> decorator) Registers aComponentdecoratorthat will act on allregisteredcomponents of the giventype, regardless of component name.default <C,D extends C>
ComponentRegistryregisterDecorator(Class<C> type, String name, int order, ComponentDecorator<C, D> decorator) Registers adecoratorthat will act onregisteredcomponents of the giventypeandnamecombination.registerDecorator(DecoratorDefinition<C, ? extends C> definition) Registers a decorator based on the givendefinition.registerEnhancer(ConfigurationEnhancer enhancer) Registers anConfigurationEnhancerwith thisComponentRegistry.registerFactory(ComponentFactory<C> factory) Registers aComponentFactorywith this registry.default <C> ComponentRegistryregisterIfNotPresent(Class<C> type, String name, ComponentBuilder<C> builder) default <C> ComponentRegistryregisterIfNotPresent(Class<C> type, String name, ComponentBuilder<C> builder, SearchScope searchScope) default <C> ComponentRegistryregisterIfNotPresent(Class<C> type, ComponentBuilder<C> builder) Registers aComponentonly if there is none yet for the giventype.default <C> ComponentRegistryregisterIfNotPresent(Class<C> type, ComponentBuilder<C> builder, SearchScope searchScope) Registers aComponentonly if there is none yet for the giventype.default <C> ComponentRegistryregisterIfNotPresent(ComponentDefinition<C> definition) default <C> ComponentRegistryregisterIfNotPresent(ComponentDefinition<C> definition, SearchScope searchScope) registerModule(Module module) Registers aModulewith this registry.setOverridePolicy(OverridePolicy overridePolicy) Sets theOverridePolicyfor thisComponentRegistry.Methods inherited from interface org.axonframework.common.infra.DescribableComponent
describeTo
-
Method Details
-
registerComponent
default <C> ComponentRegistry registerComponent(@Nonnull Class<C> type, @Nonnull ComponentBuilder<C> builder) Registers aComponentthat should be made available to othercomponentsormodulesin theConfigurationthat thisConfigurerwill result in.The given
builderfunction gets theconfigurationas input, and is expected to provide the component as output. The component will be registered under anComponent.Identifierbased on the giventype.- Type Parameters:
C- The type of component thebuilderbuilds.- 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
Configurerfor a fluent API. - Throws:
ComponentOverrideException- If the override policy is set toOverridePolicy.REJECTand 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 aComponentthat should be made available to othercomponentsormodulesin theConfigurationthat thisConfigurerwill result in.The given
builderfunction gets theconfigurationas input, and is expected to provide the component as output. The component will be registered under anComponent.Identifierbased on the giventypeandnamecombination.- Type Parameters:
C- The type of component thebuilderbuilds.- Parameters:
type- The declared type of the component to build, typically an interface.name- The name of the component to build. Usenullwhen there is no name or useregisterComponent(Class, ComponentBuilder)instead.builder- The builder building the component.- Returns:
- The current instance of the
Configurerfor a fluent API. - Throws:
ComponentOverrideException- If the override policy is set toOverridePolicy.REJECTand a component with the same type and name is already defined.
-
registerComponent
Registers aComponentbased on the givendefinition.- Type Parameters:
C- The declared type of the component.- Parameters:
definition- The definition of the component to register.- Returns:
- The current instance of the
Configurerfor a fluent API. - Throws:
ComponentOverrideException- If the override policy is set toOverridePolicy.REJECTand 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 aComponentdecoratorthat will act on allregisteredcomponents of the giventype, regardless of component name.Decorators are invoked based on the given
order. Decorators with a lowerorderwill be executed before those with a higher one. If decorators depend on the result of another decorator, theirordermust be strictly higher than the one they depend on.The order in which components are decorated by decorators with the same
orderis undefined.- Type Parameters:
C- The type of component thedecoratordecorates.D- The type of component thedecoratorreturns.- Parameters:
type- The declared type of the component to decorate, typically an interface.order- The order of the givendecoratoramong other decorators.decorator- The decoration function for a component of typeC.- Returns:
- The current instance of the
Configurerfor 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 adecoratorthat will act onregisteredcomponents of the giventypeandnamecombination.Decorators are invoked based on the given
order. Decorators with a loweorderwill be executed before those with a higher one. If decorators depend on the result of another decorator, theirordermust be strictly higher than the one they depend on.The order in which components are decorated by decorators with the same
orderis undefined.- Type Parameters:
C- The type of component thedecoratordecorates.D- The type of component thedecoratorreturns.- 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 givendecoratoramong other decorators.decorator- The decoration function for a component of typeC.- Returns:
- The current instance of the
Configurerfor a fluent API.
-
registerDecorator
Registers a decorator based on the givendefinition.- 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
Configurerfor a fluent API. - See Also:
-
hasComponent
-
hasComponent
-
hasComponent
Check whether there is aComponentregistered with thisConfigurerfor the giventypeandnamecombination.- Parameters:
type- The type of theComponentto check if it exists, typically an interface.name- The name of theComponentto check if it exists. Usenullwhen there is no name or usehasComponent(Class)instead.- Returns:
truewhen there is aComponentregistered under the giventypeandname combination,falseotherwise.
-
hasComponent
boolean hasComponent(@Nonnull Class<?> type, @Nullable String name, @Nonnull SearchScope searchScope) Check whether there is aComponentregistered with thisConfigurerfor the giventypeandnamecombination.The given
searchScopeis used to define if the search only checks thecurrentregistry, only checks allancestors, or checksboththe current registry and all ancestors.- Parameters:
type- The type of theComponentto check if it exists, typically an interface.name- The name of theComponentto check if it exists. Usenullwhen there is no name or usehasComponent(Class)instead.searchScope- The enumeration defining the search scope used to check if this registry has aComponent.- Returns:
truewhen there is aComponentregistered under the giventypeandname combination,falseotherwise.
-
registerIfNotPresent
default <C> ComponentRegistry registerIfNotPresent(@Nonnull Class<C> type, @Nonnull ComponentBuilder<C> builder) Registers aComponentonly if there is none yet for the giventype.The given
builderfunction gets theconfigurationas input, and is expected to provide the component as output. The component will be registered under anComponent.Identifierbased on the giventype.- Type Parameters:
C- The type of component thebuilderbuilds.- 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
Configurerfor a fluent API.
-
registerIfNotPresent
default <C> ComponentRegistry registerIfNotPresent(@Nonnull Class<C> type, @Nonnull ComponentBuilder<C> builder, @Nonnull SearchScope searchScope) Registers aComponentonly if there is none yet for the giventype.The given
builderfunction gets theconfigurationas input, and is expected to provide the component as output. The component will be registered under anComponent.Identifierbased on the giventype.The given
searchScopeis used to define if the search only checks thecurrentregistry, only checks allancestors, or checksboththe current registry and all ancestors.- Type Parameters:
C- The type of component thebuilderbuilds.- 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 aComponent.- Returns:
- The current instance of the
Configurerfor a fluent API.
-
registerIfNotPresent
default <C> ComponentRegistry registerIfNotPresent(@Nonnull Class<C> type, @Nullable String name, @Nonnull ComponentBuilder<C> builder) Registers aComponentonly if there is none yet for the giventypeandnamecombination.The given
builderfunction gets theconfigurationas input, and is expected to provide the component as output. The component will be registered under anComponent.Identifierbased on the giventype.- Type Parameters:
C- The type of component thebuilderbuilds.- 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
Configurerfor a fluent API.
-
registerIfNotPresent
default <C> ComponentRegistry registerIfNotPresent(@Nonnull Class<C> type, @Nullable String name, @Nonnull ComponentBuilder<C> builder, @Nonnull SearchScope searchScope) Registers aComponentonly if there is none yet for the giventypeandnamecombination.The given
builderfunction gets theconfigurationas input, and is expected to provide the component as output. The component will be registered under anComponent.Identifierbased on the giventype.The given
searchScopeis used to define if the search only checks thecurrentregistry, only checks allancestors, or checksboththe current registry and all ancestors.- Type Parameters:
C- The type of component thebuilderbuilds.- 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 aComponent.- Returns:
- The current instance of the
Configurerfor a fluent API.
-
registerIfNotPresent
Registers aComponentbased on the givendefinitiononly if there is none yet for the definition'sraw typeandnamecombination.- Type Parameters:
C- The declared type of the component.- Parameters:
definition- The definition of the component to register.- Returns:
- The current instance of the
Configurerfor a fluent API.
-
registerIfNotPresent
default <C> ComponentRegistry registerIfNotPresent(@Nonnull ComponentDefinition<C> definition, SearchScope searchScope) Registers aComponentbased on the givendefinitiononly if there is none yet for the definition'sraw typeandnamecombination.The given
searchScopeis used to define if the search only checks thecurrentregistry, only checks allancestors, or checksboththe 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 aComponent.- Returns:
- The current instance of the
Configurerfor a fluent API.
-
registerEnhancer
Registers anConfigurationEnhancerwith thisComponentRegistry.An
enhanceris able to invoke any of the methods on thisComponentRegistry, allowing it to add (sensible) defaults, decoratecomponents, 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 theComponentRegistrycreates itsConfiguration.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 duringApplicationConfigurer.build().- Returns:
- The current instance of the
Configurerfor a fluent API.
-
registerModule
Registers aModulewith this registry.Note that a
Moduleis able to access the components defined in thisComponentRegistryupon construction, but not vice versa. As such, theModulemaintains encapsulation.- Parameters:
module- The module builder function to register.- Returns:
- The current instance of the
ComponentRegistryfor a fluent API. - Throws:
ComponentOverrideException- If a module with the same name already exists.
-
registerFactory
Registers aComponentFactorywith this registry.If the
Configurationthat will contain this registry does not have a component for a givenClassand name combination, it will consult all registered component factories. Only if a givenfactorycan produce therequested typewillComponentFactory.construct(String, Configuration)be invoked. When thefactorydecides to construct a new component, it will be stored in theConfigurationfor future reference to ensure it's not constructed again.- Type Parameters:
C- The component type constructed by the givenfactory.- Parameters:
factory- The component factory to register.- Returns:
- The current instance of the
ComponentRegistryfor a fluent API.
-
setOverridePolicy
Sets theOverridePolicyfor thisComponentRegistry.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
Configurerfor a fluent API.
-
disableEnhancerScanning
ComponentRegistry disableEnhancerScanning()Completely disables scanning for enhancers on the classpath through theServiceLoadermechanism. Note that this may lead to missing framework functionality. It is recommended to disable specific enhancers throughdisableEnhancer(Class)instead. Does not affect enhancers that are registered through theregisterEnhancer(ConfigurationEnhancer)method.- Returns:
- The current instance of the
Configurerfor a fluent API.
-
disableEnhancer
Disables the givenConfigurationEnhancerclass from executing during the configuration initialization phase. This affects both enhancers registered through theServiceLoadermechanism and those registered programmatically viaregisterEnhancer(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
Configurerfor a fluent API.
-
disableEnhancer
Disables the givenConfigurationEnhancerclass from executing during the configuration initialization phase. This affects both enhancers registered through theServiceLoadermechanism and those registered programmatically viaregisterEnhancer(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
Configurerfor a fluent API.
-