@Documented @Retention(value=RUNTIME) @Target(value={TYPE,ANNOTATION_TYPE}) public @interface DomainPolicy
This annotation can be applied to an interface to declare a domain policy. Any class implementing the annotated interface will be registered by the framework as an implementation of this policy.
When a policy interface has multiple implementations, it is necessary to differentiate them
by using a different javax.inject.Qualifier
annotation on each. This qualifier can then
be used at the injection point to specify which implementation is required.
Considering the following policy:
@DomainPolicy public interface SomePolicy { double computeSomething(String someParameter); }Two different implementations can be declared as follows:
@Named("variantA") public class SomePolicyVariantA { @Override public double computeSomething(String someParameter) { // implement variant A logic } } @Named("variantB") public class SomePolicyVariantB { @Override public double computeSomething(String someParameter) { // implement variant B logic } }The "B variant" implementation can then be injected as follows:
public class SomeClass { @Inject @Named("variantB") SomePolicy somePolicy; }
Copyright © 2013-2018–2019 SeedStack. All rights reserved.