草庐IT

INJECT_EVENTS

全部标签

java - Android:Dagger 2 和构造函数注入(inject)

我是dagger的新手,我的构造函数/方法注入(inject)似乎不起作用。不起作用意味着仍然需要注入(inject)的字段。这是我的代码:@ModulepublicclassAppContextModule{privatefinalContextappContext;publicAppContextModule(ContextappContext){this.appContext=appContext;}@Singleton@ProvidespublicContextgetAppContext(){returnappContext;}}@Singleton@Component(mod

java - Dagger 2 - 构造函数注入(inject) - 作用域

我正在使用具有简单MVP模式的Dagger2。我有一个@PerApp和@PerActivity作用域。我正在使用构造函数注入(inject)来注入(inject)演示者依赖项,这使得这些演示者“可注入(inject)”(我不需要在Activity模块中编写提供方法)。代码fragment:每个应用://AppComponent@PerApp@Component(modules={AppModule.class,DataModule.class,NetworkModule.class})publicinterfaceAppComponent{LoginComponentplus(Logi

android - Dagger 2.10/2.11 注入(inject) Activity 失败

我一直在尝试将Activity注入(inject)到ViewUtils类中,但没有成功。我关注了几篇不同的帖子,但我似乎无法理解我在实现过程中遗漏了什么。我知道这可能是下面帖子的重复,对此我深表歉意,但老实说,我看不出我错过了什么。这些是我找到的帖子:Dagger2.10AndroidsubcomponentsandbuildersHowtocreatecustomscopedmodulesindagger2.10https://google.github.io/dagger/subcomponents.html我的实现如下:应用组件@Component(modules={AppMod

android - 如何创建 ViewModel 并使用 dagger 2 向其注入(inject)存储库?

我尝试理解ViewModel。我创建ViewModel:publicclassUsersViewModelextendsViewModel{privatefinalUsersRepositoryusersRepository;publicUsersViewModel(UsersRepositoryusersRepository){this.usersRepository=usersRepository;}publicLiveData>loadAll(){returnusersRepository.getAll();}}但我不明白两件事:如何将UsersRepository注入(inje

java - 用 dagger 2 查看依赖注入(inject)

我有一个扩展TextView的自定义View。我应该在哪里调用我的组件来注入(inject)View?component.inject(customTextView); 最佳答案 所以,我发现我需要在自定义View的构造函数中添加注入(inject)(在所有View中,或者让一个调用另一个)例子:publicclassCustomTextViewextendsTextView{@InjectAnyProvideranyProvider;publicCustomTextView(Contextcontext){this(context

android - 服务中的依赖注入(inject)

我正在尝试注入(inject)依赖项到我的应用程序中。一切正常,直到我尝试将Realm注入(inject)我的Service类。我开始收到IllegalStateException,这显然是由于我从创建的Thread访问Realm引起的。所以,这是我的DependencyInjection的结构AppModule@ModulepublicclassAppModule{MainApplicationmainApplication;publicAppModule(MainApplicationmainApplication){this.mainApplication=mainApplica

android - Android : Testing events? 中的 Robolectric

我已经使用robolectric编写了一些测试,现在我想做一些真正的测试类(class)。我注意到的一件事是我无法测试onCreate、onLocationChanged等事件。测试事件的标准做法是什么?我是否应该提取事件中的代码并将它们放在一个方法中,事件将调用该方法,robolectro也可以调用该方法,当然该方法需要是公共(public)的,对吗?另外,如果我想在我的方法中测试通常是私有(private)变量的东西,那么我需要添加一个公共(public)getter,对吧?我可以从robolectric检查这个吗?是否有更好的方法将数据公开给robolectric?

android - 是否可以使用 AndroidAnnotations 注入(inject)模拟以进行测试?

我还没有找到任何关于如何执行此操作的示例。基于这样的例子,我假设这是不可能的:@Bean(MyImplementation.class)MyInterfacemyInterface;要注入(inject)的类已经确定。 最佳答案 johncarl回答的补充:无法告诉AndroidAnnotations您想要注入(inject)模拟对象而不是真实对象,因为它在编译时工作,所以代码必须始终准备好生产。我建议测试生成的Activity,以补充Robolectric。注释正在向您的代码添加行为,因此您不应像没有注释一样对其进行测试。请注意测

android - 基于构建类型和风格的更好的 Dagger 依赖注入(inject)?

我正在使用方法为这个问题的回答中描述的Dagger提供模块AndroidCustomizeWorkflowforProductFlavors我们的方法有点不同-我们在debug构建类型中有Modules在src/debug/java和release中在src/release/java中构建类型。我们的主模块称为ApplicationModule,它包括所有其他模块。src/debug/java中的Modules为调试、日志记录等提供了一些自定义行为,并覆盖了ApplcationModule。现在我们需要具有基于应用程序风格的自定义行为。这样做的正确方法是什么?例如,flavorA到C应

android - roboblender-3.0.1.jar : not included in Android: javax. 工具。引用自 com.google.inject.blender.AnnotationDatabaseGenerator

我尝试构建我的android项目,我得到:Information:Gradle:Executingtasks:[clean,:app:compileDebugSources]Information:1/10/15,11:13AM-Compilationcompletedsuccessfullyin5sec然后我尝试将它部署到我的设备并获得:FAILURE:Buildfailedwithanexception.*Whatwentwrong:Executionfailedfortask':app:lint'.>Lintfounderrorsintheproject;abortingbuil