public interface InstanceLocator
InstanceProvider
should be used. This facility should be used sparingly, frequent use indicates use of the Service Locator Pattern instead of the Dependency Injection Pattern.InstanceProvider
, TypeQualifier
Modifier and Type | Field and Description |
---|---|
static String |
INSTANCE_LOCATOR_ATTRIBUTE
Denotes the name of a
HttpServletRequest attribute which if present on a request indicates an attribute whose value will be an instance of InstanceLocator |
static String |
INSTANTIATOR_TYPE_SUFFIX
Deprecated.
The
Instantiator concept has been deprecated |
Modifier and Type | Method and Description |
---|---|
static InstanceLocator |
empty()
Retrieve
InstanceLocator implementation that never produces any matches |
default <T> InstanceProvider<T> |
select(Class<T> service)
Select all services matching the specified type.
|
default <T> InstanceProvider<T> |
select(Class<T> service, Annotation... qualifiers)
Deprecated.
Use
select(TypeQualifier) instead |
<T> InstanceProvider<T> |
select(TypeQualifier<T> qualifier)
Select all services matching the specified
TypeQualifier |
static final String INSTANCE_LOCATOR_ATTRIBUTE
HttpServletRequest
attribute which if present on a request indicates an attribute whose value will be an instance of InstanceLocator
void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { // Get request scoped InstanceLocator final InstanceLocator locator = (InstanceLocator) request .getAttribute(InstanceLocator.INSTANCE_LOCATOR_ATTRIBUTE); if (locator != null) { final SomeService service = locator.select(SomeService.class); // use SomeService instance... } }
@Deprecated static final String INSTANTIATOR_TYPE_SUFFIX
Instantiator
concept has been deprecateddefault <T> InstanceProvider<T> select(Class<T> service)
select(TypeQualifier.provides(service)
T
- The type of the serviceservice
- The service to resolveInstanceProvider
for the specified type. This value is never null.@Deprecated default <T> InstanceProvider<T> select(Class<T> service, Annotation... qualifiers)
select(TypeQualifier)
insteadT
- The type of the service to locateservice
- The type (contract) of the service to retrievequalifiers
- Additional qualifiers that constrain which implementation to matchInstanceProvider
for the specified type and qualifiers. This value is never null.<T> InstanceProvider<T> select(TypeQualifier<T> qualifier)
TypeQualifier
T
- The type of the service to locatequalifier
- The qualifier that constrains which implementation to matchInstanceProvider
for the specified type and qualifier. This value is never null.static InstanceLocator empty()
InstanceLocator
implementation that never produces any matchesInstanceLocator
instance