@Documented @Retention(value=RUNTIME) @Target(value={METHOD,FIELD}) public @interface Provides
public class MyService {
@Inject
public MyService( ... ) { ... }
@Provides
public OtherService other() {
return new OtherService( ... );
}
}
ServiceLocator locator =
ServiceLocatorUtilities.createAndPopulateServiceLocator();
ServiceLocatorUtilities.addClasses(
locator,
ProvidesListener.class,
MyService.class);
OtherService other = locator.getService(OtherService.class);
The contracts of the provided service are, by default, defined by the
method return type of the
annotated method or the field type of the
annotated field. These default contracts can be overridden using contracts().
The providing class is responsible for initializing instances of the
provided service. The system will not automatically invoke a PostConstruct.postConstruct() method declared by the provided service.
If the annotated member is a method, then disposal of the provided service
may be customized. See disposeMethod(). If the annotated member is
a field, then the provided service will not undergo automatic disposal.
The scope of the provided service is:
Scope annotation on the method or field, if present.
Scope annotation on the method return type or the field type, if present.
PerLookup.
| Modifier and Type | Optional Element and Description |
|---|---|
Class<?>[] |
contracts
If non-empty, specifies a list of contracts provided that overrides the
default contracts.
|
Provides.DisposalHandledBy |
disposalHandledBy
Specifies who is responsible for the disposal of instances of the provided
service, assuming that
disposeMethod() is non-empty. |
String |
disposeMethod
If non-empty, specifies the name of the method to be invoked when disposing
of an instance of the provided service.
|
public abstract Class<?>[] contracts
ContractsProvided.
If empty, then the default contracts for the provided type will be used.
public abstract String disposeMethod
disposalHandledBy().
If empty, then the default pre-destroy behavior for the provided type
will be used. If the provided type implements PreDestroy for
example, then its PreDestroy.preDestroy() method will be invoked.
This value is ignored when this annotation is applied to a field.
public abstract Provides.DisposalHandledBy disposalHandledBy
disposeMethod() is non-empty. If disposeMethod() is empty or this annotation is applied to a field, then
this value is ignored.
See Provides.DisposalHandledBy for definitions of the possible values.
Copyright © 2009–2020 Oracle Corporation. All rights reserved.