私は PicoContainer を使用しており、パラメーターを持つコンストラクターを持つコンポーネントを追加する必要があります。ので、私は持っています
public abstract class IA {
@Inject
protected B b;
public void useB(){
b.useSomeMethodOfB();
}
}
public interface IC{}
public class C implements IC{}
public class A extends IA{
private IC mSomeOtherComponent;
public A(IC someOtherComponent){
mSomeOtherComponent = someOtherComponent
}
}
今私が持っているこのコンポーネントを開始するために:
MutablePicoContainer context = new PicoBuilder().withAnnotatedFieldInjection().withCaching().build();
それから
contex.addComponent(A.class, new A(new C()));
しかし、抽象クラスで useB() メソッドを呼び出すと、null が返され、何も注入されません。コンポーネントを追加した方法が正しくないと思います。私も試しました。
ComponentParameter pr = new ComponentParameter(new C());
context.addComponent(IA.class, A.class, pr);
と
ComponentParameter pr = new ComponentParameter(new C());
context.addComponent(A.class, A.class, pr);
しかし、「AにはフィールドBに対する依存関係が満たされていません。
どうすれば解決できますか?