users@hk2.java.net

Re: ServiceLocator.getService() failing for _at_Service-annotated classes

From: John Wells <john.wells_at_oracle.com>
Date: Thu, 05 Dec 2013 16:06:38 -0500

It searches for all of them and if there are more than one of them it'll
pick one based on priority rules (ranking, oldest service from most
leaf-like locator (if you have parented service locators))

On 12/5/2013 4:00 PM, cowwoc wrote:
> Mason,
>
> When you getService(contract), and are using the inhabitant generator,
> how does it know which @Contract links to what @Service?
>
> Gili
>
> On 05/12/2013 3:37 PM, Mason Taube wrote:
>> At least in GlassFish, it is most common use case is to do a
>> .getService (or Injection) specifying a contract name (that is either
>> an interface or an abstract class annotated with @Contract). The
>> implementing (@Service) class is usually not known at runtime.
>>
>> Its an interesting idea, but can’t replace the inhabitant generator
>> in the general case.
>>
>> On Dec 5, 2013, at 1:09 PM, cowwoc <cowwoc_at_bbs.darktech.org
>> <mailto:cowwoc_at_bbs.darktech.org>> wrote:
>>
>>> I just had a thought: why do we need hk2-inhabitant-generator at
>>> all? When someone tries to inject a class and a binding is not
>>> found, couldn't HK2 automatically add a binding and retry the
>>> operation if the class is annotated with @Service? Meaning, what
>>> prevents you from adding the binding on-the-fly at runtime?
>>
>>
>