users@hk2.java.net

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

From: cowwoc <cowwoc_at_bbs.darktech.org>
Date: Thu, 05 Dec 2013 16:00:36 -0500

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