2

我在我的一个项目中尝试使用匕首,我遇到了这种情况:“只有在我将类声明为模块定义中的入口点时,字段注入才有效。”

这是正确的行为吗?

如果 Messenger.class 未声明为入口点,则以下依赖项不会注入 Messenger 类。构造函数注入器工作正常,但我不想声明多参数构造函数。

public class Messenger implements NetworkInterfaceListener {
  @Inject public NetworkInterface networkInterface;
  @Inject public MessageFactoryInterface messageFactory;
  @Inject public Bus bus;
  @Inject public Logger log;
  ...
  ...
}
4

1 回答 1

3

You have only two alternatives: either to declare injectable constructor with all params to be injected or enlist class into entryPoints (now called injects) of your dagger module and call mGraph.inject(this) in default constructor (or whenever you need to actually "inject" maybe even outside the class).

于 2013-10-05T17:17:20.780 回答