如何将工厂绑定到注释合格的注入点? [英] How can I bind a factory to a annotation-qualified injection point?

查看:119
本文介绍了如何将工厂绑定到注释合格的注入点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

询问,并得到了如何绑定命名注入点的答案.

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;
}

我准备了一家工厂

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.

推荐答案

我需要一个用于限定符注释的实现.

I need an implementation for the qualifier annotation.

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

以便我可以这样使用.

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.

这篇关于如何将工厂绑定到注释合格的注入点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆