users@hk2.java.net

Re: ServiceLocator Parent?

From: John Wells <john.wells_at_oracle.com>
Date: Fri, 03 Jan 2014 07:24:05 -0500

ServiceLocators are given parents when they are created. See:
https://hk2.java.net/2.2.0-b27/apidocs/org/glassfish/hk2/api/ServiceLocatorFactory.html#create%28java.lang.String,%20org.glassfish.hk2.api.ServiceLocator%29

A ServiceLocator with a parent can see all of the services of the parent
along with its own services. (Well, services can be marked as being
LOCAL, in which case even the children can not see it).

Do you have a use case where you want to be able to dynamically set the
parent of a service locator? That's not a bad idea, but we would need a
feature request and a good use case. Perhaps you have a specific use
case in mind, or can enter a Jira here:

https://java.net/jira/browse/HK2

Thanks!

On 1/3/2014 1:46 AM, buko wrote:
>
> Apparently ServiceLocators can have parents but it's not clear how to
> use them. I have a case where I have a module that I'd like to reuse
> across several ServiceLocators. I could instantiate this same module
> over and over and bind it into each ServiceLocator but this is not
> ideal. It'd be nice to define a root ServiceLocator with the parent
> module bound and have each child/agent ServiceLocator use the root as
> a parent.
>
> It's not clear how to specify the parent of a ServiceLocator. None of
> the methods on ServiceLocatorUtilities seem to take a parent. There's
> one that does take another ServiceLocator but it's not clear this does
> the right thing.
>
> Any suggestions?