Annotation Interface Service.PreDestroy
- Enclosing class:
Service
Behavior of this annotation may differ based on the service registry implementation used. For example when using Helidon Service Inject (to be introduced), a pre-destroy method would be used when the scope a service is created in is finished. The core service registry behaves similar like a singleton scope - instance is created once, and pre-destroy is called when the registry is shut down. This also implies that instances that are NOT created within a scope cannot have their pre-destroy methods invoked, as we do not control their lifecycle.
A pre-destroy method is intended to release resources held by the service instance, not to interact with other services.
It must not invoke methods that may instantiate another service, such as an instance lookup on an injected
ServiceRegistry.
For compatibility with previously generated services, an injected Supplier may return
an already initialized, still-active dependency from the same scope instance during the callback. Such access is limited to
the callback thread and fails if resolution would create a service, invoke a factory, or wait for initialization.
The dependency's scope must still be resolvable during cleanup.
Prefer retaining dependencies needed for cleanup while the service is active.
The method must not have any parameters and must be accessible (not private).