In HK2 the basic example code for configuring injection is this (within a class that extends AbstractBinder
:
bind(BuilderHelper
.link(FooImpl.class) // the class of the object to be injected
.to(FooInterface.class) // identifies what @Inject fields to link to
.build());
This causes HK2 to call the constructor FooImpl()
when it needs to create a FooInterface
.
What if FooImpl doesn't have a constructor?
- What if it's intended to be instantiated with a static factory method
FooImpl.getInstance()
- What if it's intented to be instantiated by a factory object
fooFactory.create()
I see that ResourceConfig
has a method bind(FactoryDescriptors factoryDescriptors)
but it is not clear to me what the idiom is for building a FactoryDescriptors
object, and have not been able to find any examples online.