users@hk2.java.net

Re: Injecting Type Variable Fields

From: john wells <john.wells_at_oracle.com>
Date: Mon, 08 Jun 2015 17:40:34 -0400

I'd have to see the exact code where you were binding the services. I am
also surprised that this does not work.

On 6/8/2015 4:24 PM, Mirko Raner wrote:
> Hi all,
>
> I have a hierarchy of message handlers, where each concrete message
> handler needs a specific message translator injected (following DDD
> principles):
>
> abstract class MessageHandler<T> {
> @Inject
> protected T translator;
>
> abstract void handle(Object object);
> }
>
> class MyMessageHandler extends MessageHandler<MyTranslator> {
> void handle(Object object) {
> DomainObject domainObject = translator.translate(object);
> }
> }
>
> I would expect that HK2 would be able to resolve this injection,
> because, when injecting into MyMessageHandler, T is already bound to
> MyTranslator. However, I get the exception "Invalid injectee with
> required type of T passed to getInjecteeDescriptor".
> The handlers, as well as the translators, are all bound via
> addActiveDescriptor(...).
>
> Am I missing something here? Is this just a limitation of HK2's
> current resolution mechanism, or is there some conceptual problem here?
>
> Thanks for clarifying,
>
> Mirko
>