eclipse-ee4j / glassfish-hk2

Dynamic dependency injection framework
https://eclipse-ee4j.github.io/glassfish-hk2
Other
84 stars 55 forks source link

Lifecycle events for Immediate scope services #1016

Open benfortuna opened 5 months ago

benfortuna commented 5 months ago

This is more a question than an issue.

Is there a way to track the lifecycle of Immediate scope services such that I can block until all Immediate services are initialized?

I want to be able to do something like this:

ServiceLocator serviceLocator = ServiceLocationUtilities.createAndPopulateServiceLocator();
ServiceLocatorUtilities.enableImmediateScope(serviceLocator);

// 1. wait until Immediate scope services have loaded..

// 2. continue application logic

I could call serviceLocator.getService(..) on each of the Immediate scope services, but then they don't really need to be Immediate. And also for my use case I won't have access to the full list as it would be defined in a separate module.

I notice the comment on ServiceLocatorState says to "assume future states will be added" - could this include a PENDING state or equivalent prior to RUNNING where Immediate scoped services are being loaded?