dagger-2

What are the advantages of using DispatchingAndroidInjector<> and the other dagger.android classes?

爷,独闯天下 提交于 2019-12-10 03:54:39
问题 I'm working on setting up Dagger 2 into my android project. It is my first time with this framework and everything goes well so far. But I'm seeing different approaches on the way you can set up this framework in your project and I wonder which one is better, because I compare both and for me the result is kind of the same. I followed this guide: https://github.com/codepath/android_guides/wiki/Dependency-Injection-with-Dagger-2 Searching on Internet all of them use this approach. It use

Using Dagger2 with Lombok

喜夏-厌秋 提交于 2019-12-09 16:43:42
问题 Has anyone used Lombok 1.16 with Dagger2? My current code looks like: @AllArgsConstructor(onConstructor = @__(@Inject)) public class JuiceMaker { private final Apple apple; The error is: JuiceMaker cannot be provided without an @Inject constructor or from an @Provides-annotated method. Without the Lombok annotation this actually works, so: public class JuiceMaker { private final Apple apple; @Inject public JuiceMaker(Apple apple){ this.apple = apple } } works 回答1: This is a copy paste version

How to resolve a circular dependency while still using Dagger2?

筅森魡賤 提交于 2019-12-09 14:46:03
问题 I have two classes, Foo<T> and Bar , which depend on each other, as well as various other classes. I am using Dagger-2 for dependency injection, but if I naively add the circular dependency, Dagger hits a stack overflow at runtime. What's a good way to refactor the classes to fix this, while still using Dagger to inject all the other dependencies, and with minimal duplication and changes to existing calls? 回答1: The easy way out is to use Lazy<T> on one side. Lazy<Foo> foo; @Inject Bar(Lazy

Android Mocking a Dagger2 injected dependency for a Espresso test

北城以北 提交于 2019-12-09 11:29:16
问题 I have a heavily dependency injected ( dagger2 ) application. I would like to run an espresso test without having the test navigate through the whole application, and log into the application. I would like to start on my teleActivity, and mock the login manager. However in any @test function, we have already hit the null pointer as we have called onCreate. If I override it before we launch the activity (show below) the activity is null. To my understanding, the ability to switch our

Error:Execution failed for task ':app:kaptDebugKotlin'

こ雲淡風輕ζ 提交于 2019-12-09 08:55:55
问题 I'm new to using Kotlin and trying to set it up with Dagger2, I've seen some few examples but none of them seem to work for me. I keep getting this Error:Execution failed for task ':app:kaptDebugKotlin'. Internal compiler error. See log for more details I have my build.gradle (Module: app) apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 25 buildToolsVersion "25.0.0"

Getting rid of Dagger 2 warning “Generating a MembersInjector”

邮差的信 提交于 2019-12-09 07:38:30
问题 Given the following classes abstract class AbstractClass { @Inject SomeDependency someDependency; } class SomeClass extends AbstractClass { @Inject AnotherDependency anotherDepenency; public void onCreate() { component = // Get component instance somehow component.inject(this); } } in Dagger 2 when injecting dependencies into a class which extends from an abstract base class which also contains dependencies, Dagger shows a warning of the kind Generating a MembersInjector for AbstractClass.

Kodein vs Dagger - Can't Get Dagger Working w/ Multiple Modules

北慕城南 提交于 2019-12-09 05:07:25
( x-post from /r/androiddev ) I would just like to preface this by saying that this is not a "which is better" post; this is strictly a question about how I can build something using Dagger (and how I built it in Kodein to help illustrate the problem). I've been using Kodein for a few years now in several work projects, and I've found it to be so easy to work with, that I never look at Dagger anymore. I started a new personal project, and I thought I'd give Dagger another shot. To keep things simple, I have 3 modules (this is a regular desktop app not an Android one); app common google app

ERROR : error.NonExistentClass Kotlin In multi module Dagger project

可紊 提交于 2019-12-09 02:09:02
问题 I'm using Dagger 2 and Kotlin for Android development. My project is also a multi-module project. My settings.gradle file is like this: include :app include :lib I'm also maintaining the lib module. In the Dagger Files (for example in the component), I try to get the item from other module. For example: @Component interface AppComponent{ fun getPresenter() : Presenter } The Presenter object is defined in lib module. I was working in linux environment and I'm using Android Studio 3 preview

Dagger 2 create singleton instance

巧了我就是萌 提交于 2019-12-08 21:10:30
Consider the scenario that I am calling Webservice at Presenter A and holding the response data at the same Presenter. I want to utilize the same response data at Presenter E. But I cant pass the response object to each presenter B, C, D. So, I tried to store my response object at separate Holder class with getter & setter. I initialized Holder class using Dagger Inject constructor annotation and tried to consume it at Presenter E . But I got Empty response instead of my datas . Can any one suggest me to handle this scenario in best way . Thanks in advance You have a lot of fundamental

Creating test dependencies when using Dagger2

送分小仙女□ 提交于 2019-12-08 15:46:49
问题 While reading the docs for dagger 2 I cannot find an easy way to provide a dependency when building an app for testing. The only clue I've found is this: Dagger 2 doesn't support overrides. Modules that override for simple testing fakes can create a subclass of the module to emulate that behaviour. Modules that use overrides and rely on dependency injection should be decomposed so that the overridden modules are instead represented as a choice between two modules. I don't understand how I