Module io.helidon.service.registry
Package io.helidon.service.registry
Annotation Interface Service.Provider
- Enclosing class:
Service
@Documented
@Retention(CLASS)
@Target({TYPE,ANNOTATION_TYPE})
@Inherited
@Deprecated(forRemoval=true,
since="4.2.0")
public static @interface Service.Provider
Deprecated, for removal: This API element is subject to removal in a future version.
A service provider. This is similar to
ServiceLoader
service providers.
The provider is an implementation of a Service.Contract
that is discoverable by
the service registry.
A service provider annotated with this annotation must provide either of:
- an accessible no-argument constructor (package private is sufficient), and must itself be at least package private
- an accessible constructor with arguments that are all services as well
Contract
- obtain an instance of a service providing that contractOptional<Contract>
- the other service may not be availableList<Contract>
- obtain all instances of services providing the contractSupplier<Contract>
- and suppliers of all above, to break instantiation chaining, and to support cyclic service references, just make sure you call theget
method outside of the constructor
- Direct implementation of interface (or extending an abstract class)
- Implementing a
Supplier
of the contract; when using supplier, service registry supports the capability to returnOptional
in case the service cannot provide a value; such a service will be ignored and only other implementations (with lower weight) would be used. Supplier will be called each time the dependency is used, or each time a method on registry is called to request an instance. If the provided instance should be singleton-like as well, useLazyValue
or similar approach to create it once and return the same instance every time
Service.Singleton
,Service.PerLookup
).