Replies: 1 comment
-
|
/cc @radcortez (config) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We introduced Quarkus since a few weeks for our application and are very happy with it. I would like some guidance on how to best solve a very common requirement.
Setup
Solutions
Since we deploy the same build in different environments, solutions with
@IfBuildProfile,@UnlessBuildProfile,@IfBuildPropertyor@UnlessBuildPropertydo not work for us.We have successfully tested the following implementations.
Property
We can control via the property
quarkus.arc.selected-alternativeswhich implementation of an interface is instantiated. This property can be set depending on the environment.@TypedWe annotate the implementations with
@Typedand set the class of the implementation as value.We write a producer-class for the interface which injects all implementations of the interface in own private variables. In the producer-implementation we read the configuration and return the respective injected implementation.
@NamedWe annotate the implementations of the interface with
@Namedand set a String as the value.We create a class extending
AnnotationLiteralwithNamedimplementingNamed.We create a producer-class in which an
Instanceof the interface is injected with@Any. In the producer-method, depending on the configuration we create the correct object of the extendedAnnotationLiteraland use this to select the respective instance and get the instantiated object. Also, the producer-method needs to be annotated with@Alternativeand@Priority(1)so that the producer method is selected when the interface is injected in a resource.Qualifier interface
We created an own
Qualifier-annotation which has an ENUM as value.We created a class extending the
AnnotationLiteralwith our enum implementing the annotation.We create a producer-class in which an
Instanceof the interface is injected. In the producer-method, depending on the configuration we create the correct object of the extendedAnnotationLiteraland use this to select the respective instance and get the instantiated object.Question
Which of the above solutions is the canonical one?
Is there another approach/pattern which we do not see?
Beta Was this translation helpful? Give feedback.
All reactions