Annotation 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);
Contracts
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().
Lifecycle
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.
Scope
The scope of the provided service is:
- The
Scopeannotation on the method or field, if present. - Otherwise, the
Scopeannotation on the method return type or the field type, if present. - Otherwise, if the method or field is non-static, the scope of the containing service.
- Otherwise,
PerLookup.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSpecifies who is responsible for the disposal of instances of a service. -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionClass<?>[]If non-empty, specifies a list of contracts provided that overrides the default contracts.Specifies who is responsible for the disposal of instances of the provided service, assuming thatdisposeMethod()is non-empty.If non-empty, specifies the name of the method to be invoked when disposing of an instance of the provided service.
-
Element Details
-
contracts
Class<?>[] contractsIf non-empty, specifies a list of contracts provided that overrides the default contracts. Similar toContractsProvided.If empty, then the default contracts for the provided type will be used.
- Default:
- {}
-
disposeMethod
String disposeMethodIf non-empty, specifies the name of the method to be invoked when disposing of an instance of the provided service. The class whose method is to be invoked is specified bydisposalHandledBy().If empty, then the default pre-destroy behavior for the provided type will be used. If the provided type implements
PreDestroyfor example, then itsPreDestroy.preDestroy()method will be invoked.This value is ignored when this annotation is applied to a field.
- Default:
- ""
-
disposalHandledBy
Provides.DisposalHandledBy disposalHandledBySpecifies who is responsible for the disposal of instances of the provided service, assuming thatdisposeMethod()is non-empty. IfdisposeMethod()is empty or this annotation is applied to a field, then this value is ignored.See
Provides.DisposalHandledByfor definitions of the possible values.- Default:
- PROVIDED_INSTANCE
-