users@hk2.java.net

Binding API is too difficult to use

From: cowwoc <cowwoc_at_bbs.darktech.org>
Date: Mon, 02 Dec 2013 17:45:32 -0500

Hi,

I'm attempting to migrate code from Guice to HK2. I wanted to share an
outsider's point of view on the API.

While I appreciate how much more powerful HK2's binding model is than
Guice, I find it to be a total mess for basic use-cases.

I found the following classes related to binding:

  * Binder
  * AbstractBinder
  * BuilderHelper
  * AbstractBindingBuilder
  * Descriptor
  * DescriptorImpl
  * AbstractActiveDescriptor

and there are others. It seems I'm not the only one who is confused. See
http://stackoverflow.com/q/17396165/14731 and
http://stackoverflow.com/a/20128336/14731.

What makes it worse is that some functionality is available one class,
but other functionality is available in another class (e.g.
bindFactory() in AbstractBinder but
BuilderHelper.createConstantDescriptor() for constants). Many of these
classes add very little code before redirecting to one another. Please
refactor all this functionality under the DynamicConfiguration class and
hide all the implementation details under the hood.

I ran into this problem while trying to solve three simple use-cases:

  * Binding of type to constant/instance, with qualifier, in scope.
  * Binding of a Factory
  * Binding of a JSR 330 Provider

Thanks,
Gili