Hi! In this blog, we will talk about the parameter resolvers in axon which help us build and model complex business entities required for the CQRS framework.
What is Axon?
It is a Java Framework, It allows to build of DDD (Domain Driven Design), CQRS (Command Query Responsibility Separation), and Event Sourcing as well.
It helps in building several microservices from the system which would be easy to handle for future perspectives as well.
For learning more about Axon you can refer to our previous blog which has an introduction to it.
Need of parameter resolver?
Axon supports message-based commands, In some cases, these messages can be handled easily if they have the required information present within, but in most cases, these messages require some external handlers to handle their external dependencies and inject them whenever they are required.
Therefore here comes the requirement of Parameter Resolvers, It helps in injecting all the dependencies to the message-handlers.
How is the injection of dependencies done in the message-handler?
- Components used to perform this function:
- Parameter Resolver
- Parameter Resolver Factory
- Parameter Resolver Factory helps in creating the instance of parameter resolver.
Iterations are being done on the provided parameter list with the use of the Parameter Resolver factory and the required parameters are chosen accordingly which can handle the dependencies.
From the whole process, we can understand that the planning of Axon framework is in such a manner that before resolving the messages it initially resolves all the parameters as a part of prerequisites.
Frequently used ParameterResolverFactory:
Need for MultiParameterResolverFactory
In some cases as per the system requirements, we require several parameters, and they are defined in multiple parameter factories, therefore for handling such a large number of parameter factories the concept of MultiParameterResolverFactory came into the picture. So that parameter resolvers can work in an efficient manner in those cases as well.
Need of AbstractAnnotatedParameterResolverFactory
In most cases when the parameters are in the annotated format then we can make use of AbstractAnnotatedParameterResolverFactory, it helps in defining the parameters in annotated format only and mapping is done accordingly for parameters.
AbstractAnnotatedParameterResolverFactory makes use of:
public void mappingFor( @Timestamp timestamp) //resolves timestamp public void mappingFor( @SequenceNumber numbers ) //resolves sequesces of the messages public void mappingFor( @MessageIdentifier message ) //resolves identifiers i.e commands/queries etc public void mappingFor( @ConcludeBatch conclusion ) //returns true if parameter is last one from the group
Parameter Resolver Factories provided by the Axon Framework
We have discussed the two factories above so far.
In our upcoming blog, we would try to deep dive more in detail regarding the remaining ParameterResolverFactories as well
We discussed at the start of the blog Axon provides an easy way to handle all the parameters and resolves all the dependencies (maybe in form of components or variables) to complete the task, in this way the messages are provisions effectively and in a much simple way.
We don’t need to write so much code to resolve the parameters, Axon can handle them with the help of the parameter resolver