How can I bind a factory to a annotation-qualified injection point?

情到浓时终转凉″ 提交于 2019-12-11 03:06:15

问题


I asked and got an answer how to bind a named injection point.

And I don't know how to bind a factory to a qualified injection point.

class SomeResource {

    @Inject
    @Some // is a @Qualifier, of course.
    private MyType qualified;
}

I prepared a factory

class SomeFactory extends Factory<MyType> {
}

And I stuck on creating a binder for that

class SomeBinder extends AbstractBinder {
    @Override protected void configure() {
        // @@?
    }
}

I actually want to know how to use ServiceBindingBuilder#qualifiedBy.


回答1:


I need an implementation for the qualifier annotation.

public class Some_
    extends AnnotationLiteral<Some>
    implements Some {
}

So that I can use like this.

bindFactory(Someactory.class)
    .qualifiedBy(new Some_())
    .to(MyType.class);

I really don't understand why ServiceBindingBuilder doesn't have a method taking an annotation class not an instance.



来源:https://stackoverflow.com/questions/29767581/how-can-i-bind-a-factory-to-a-annotation-qualified-injection-point

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!