使用注释和键类的Google Guice绑定

问题描述 投票:0回答:1

假设我们有Ampl.java实现的A.java接口和Bimpl.java]实现的B.java

以上类被绑定到两个模块中,如下所示

Module1 {
    bind(A.class).to(AImpl.class);
    bind(B.class).to(BImpl.class);
}

Module2 {
    Key<A> aKey = Key.get(A.class, AnAnnot.class);
    bind(aKey).to(AImpl.class);
    Key<B> bKey = Key.get(B.class, AnAnnot.class);
    bind(bKey).to(BImpl.class);
}


Class AImpl implements A {
}

Class BImpl implements B {

@Inject
BImpl(A aImpl) {
 //??
}
}

BImpl指的是A

对于使用注释进行绑定的BImpl,我想要使用注释进行绑定的相应aImpl,但是在这里,我得到的是未使用注释进行绑定的aImpl

请建议

假设我们有一个由AImpl.java实现的A.java接口和一个由Bimpl.java实现的B.java接口,下面的类绑定在两个模块中,如下所示。Module1 {bind(A.class).to(AImpl.class); ...

binding annotations guice
1个回答
0
投票

我能够使用以下模式来实现。可能会有更简单的方法。很高兴知道更多

© www.soinside.com 2019 - 2024. All rights reserved.