Package oracle.dbtools.plugin.api.di
Interface InstanceLocator
- All Known Implementing Classes:
Instances,Instances.Builder
public interface InstanceLocator
Allows the application to dynamically obtain instances of services with a
specified combination of required type and qualifiers.
In general it is preferred to use injection to resolve dependencies, but in
certain situations, injection is not the most convenient way to obtain a
service instance. For these cases
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.- Author:
- cdivilly
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDenotes the name of aHttpServletRequestattribute which if present on a request indicates an attribute whose value will be an instance ofInstanceLocatorstatic final StringDeprecated. -
Method Summary
Modifier and TypeMethodDescriptionstatic InstanceLocatorempty()RetrieveInstanceLocatorimplementation that never produces any matchesdefault <T> InstanceProvider<T>Select all services matching the specified type.default <T> InstanceProvider<T>select(Class<T> service, Annotation... qualifiers) Deprecated.Useselect(TypeQualifier)instead<T> InstanceProvider<T>select(TypeQualifier<T> qualifier) Select all services matching the specifiedTypeQualifier
-
Field Details
-
INSTANCE_LOCATOR_ATTRIBUTE
Denotes the name of aHttpServletRequestattribute which if present on a request indicates an attribute whose value will be an instance ofInstanceLocatorvoid 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... } } -
INSTANTIATOR_TYPE_SUFFIX
Deprecated.TheInstantiatorconcept has been deprecatedIdentifies the expected type name suffix for any type that can instantiate another type. See Accelerating Instantiation for more information on this topic.- See Also:
-
-
Method Details
-
select
Select all services matching the specified type. Equivalent toselect(TypeQualifier.provides(service)- Type Parameters:
T- The type of the service- Parameters:
service- The service to resolve- Returns:
InstanceProviderfor the specified type. This value is never null.- Since:
- 19.3.0
-
select
Deprecated.Useselect(TypeQualifier)insteadObtains a child Instance for the given required type and additional required qualifiers.- Type Parameters:
T- The type of the service to locate- Parameters:
service- The type (contract) of the service to retrievequalifiers- Additional qualifiers that constrain which implementation to match- Returns:
InstanceProviderfor the specified type and qualifiers. This value is never null.
-
select
Select all services matching the specifiedTypeQualifier- Type Parameters:
T- The type of the service to locate- Parameters:
qualifier- The qualifier that constrains which implementation to match- Returns:
InstanceProviderfor the specified type and qualifier. This value is never null.- Since:
- 19.3.0
-
empty
RetrieveInstanceLocatorimplementation that never produces any matches- Returns:
- empty
InstanceLocatorinstance - Since:
- 19.3.0
-
Instantiatorconcept has been deprecated