@ApplicationScoped public class DynamicCdiLoader extends Object
To 'activate' DynamicCdiLoader in a CDI project, add a new class that extends from it in a beans enabled module.
Implementations to be found by the DynamicCdiLoader must implement the tag interface DynamicCdi. They should implement another interface for the Service they implement (so we can have different implementations at all).
They can optionally define an annotation DynamicCdiTag with a String value. If they do, this implementation will be loaded if the tag is activated.
A tag can be activated either by specify a property with the full class name as its key and the tag as its
value or by specifying the default tag using the property ju.ee.cdi.defaultDynamicCdiTag
If no tag is specified, the default value '-' will be used which stands for the default implementation.
Important:Every dynamic implementation has to extend the interface DynamicCdi AND to specify a tag DynamicCdiTag. We need the tag to avoid duplicate declaration issues with weld. When we use a producer to lookup the actual implementation, it will not have a tag thus making the declaration unambiguous.
| Constructor and Description |
|---|
DynamicCdiLoader() |
DynamicCdiLoader(javax.enterprise.inject.Instance<DynamicCdi> dynamicCdis)
A Producer of DynamicCdiLoader will need to get Instance
@Inject @Any |
public DynamicCdiLoader()
public DynamicCdiLoader(javax.enterprise.inject.Instance<DynamicCdi> dynamicCdis)
@Inject @AnydynamicCdis - public <T> T getImplementation(Class<T> clazz)
This method is mainly public so we can test it from the esw-test1 package. Normally, it will not be called from outside.
clazz - Clazz to get implementation for (i.e. CDI instance with the appropriate SimulatorTag)ServiceDbRuntimeException - If no implementation can be foundCopyright © 2014. All rights reserved.