we have implemented a framework that uses hk2 with custom annotations to inject objects in our rest services classes. Now we want to inject objects also if the annotations are present inside the injected objects in a recoursive way. Is there a clean way to do this with hk2? or must I use another library? in this case, which library can solve this task (we need a library as light as possible) ? Thank you for reply
UPDATE
The framework we have implemented is very similar to the one explained by @peeskillet in this post. Follows the explanation of my needs:
For example I have a service that use @myCustomAnnotation like this:
@Path("/test")
public class RestService implements IRestService {
@myCustomAnnotation
private TestObject object;
@GET
@Path("/myTestObject")
public TestObject getMyObject(){
return object;
}
}
All works fine.
My problem is this:
If I have into the TestObject class definition, another object that uses @myCustomAnnotation, such as:
public class TestObject {
@myCustomAnnotation
private AnotherObject object;
public AnotherObject getObject(){
return object;
}
}
it isn't injected, so the AnotherObject object is always null.
I have, into the resolve method of the InjectionResolver, the resolution of the 2 kind of objects:
public Object resolve(Injectee injectee, ServiceHandle<?> handle) {
Object result=null;
if (TestObject.class == injectee.getRequiredType()) {
result = systemInjectionResolver.resolve(injectee, handle);
} else if (AnotherObject.class == injectee.getRequiredType()) {
result = systemInjectionResolver.resolve(injectee, handle);
}
return result;
}
I hope I was clear.