【问题标题】:Roboguice Inject into POJO将 Roboguice 注入 POJO
【发布时间】:2015-02-04 23:20:02
【问题描述】:

在我的应用程序中,我使用 RoboGuice 进行依赖注入。在我的 RoboActivities 中,注入工作正常。如果我想在 POJO 中注入一些东西,例如:

public class EventController {
    @Inject
    UserController userController;

    @Inject
    public EventController() {}

    public void doSomethingWithUserController {
        //userController is null here
        userController.doSomething();
    }
}

这样做我的 userController 是空的。我需要做什么才能将 UserController 注入到这个 POJO 中?

提前致谢!

【问题讨论】:

    标签: android dependency-injection roboguice


    【解决方案1】:

    你必须调用它

    RoboGuice.getInjector(Context).injectMembers(this);
    

    在 EventController 的构造函数中。并从您的构造函数中删除 @Inject 注解。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多