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| 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
Identifies the expected type name suffix for any type that can instantiate another type.
|
| Modifier and Type | Method and Description |
|---|---|
<T> InstanceProvider<T> |
select(Class<T> instanceType, Annotation... qualifiers)
Obtains a child Instance for the given required type and additional required qualifiers.
|
static final String INSTANTIATOR_TYPE_SUFFIX
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...
}
}
<T> InstanceProvider<T> select(Class<T> instanceType, Annotation... qualifiers)
T - The type of the service to locateinstanceType - 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.