users@hk2.java.net

Re: ServiceLocator Parent?

From: buko <buko_at_chiubarobot.com>
Date: Fri, 3 Jan 2014 09:58:31 -0500

I'm not trying to dynamically set the parent of a ServiceLocator, I'm just
trying to specify its parent at creation time. Usually I create
ServiceLocators using the ServiceLocatorUtilities class but I don't see a
method on that class that lets me specify a parent service locator. Ideally
I'd like to be able to do:

ServiceLocator parent = ServiceLocatorUtilities.bind(... common modules and
services...);
ServiceLocator child = ServiceLocatorUtilities.bind(parent, ...
app-specific modules...);


Is there another way to create a ServiceLocator and specify a parent?


On Fri, Jan 3, 2014 at 7:24 AM, John Wells <john.wells_at_oracle.com> wrote:

> 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?
>>
>
>