dagger

Specifying order of annotation processors

霸气de小男生 提交于 2019-11-26 20:09:32
问题 I'm trying to run Dagger 2 as well as Lombok on my Java project. Lombok has to run first, of course, but whether it actually does seems to be up to chance. At first I suspected I could specify the order by the respective position of the library jars in the class path, but that order evidently gets ignored. Is there a way to specify the order for them to run somehow, or do I simply have to live with not being able to combine two APs ? I have produced an SSCCE test case. A simple git clone &

How to set up DAGGER dependency injection from scratch in Android project?

末鹿安然 提交于 2019-11-26 19:17:48
How to use Dagger? How to configure Dagger to work in my Android project? I'd like to use Dagger in my Android project, but I find it confusing. EDIT: Dagger2 is also out since 2015 04 15, and it's even more confusing! [This question is a "stub" on which I am adding to my answer as I learned more about Dagger1, and learn more about Dagger2. This question is more of a guide rather than a "question".] EpicPandaForce Guide for Dagger 2.x (Revised Edition 6) : The steps are the following: 1.) add Dagger to your build.gradle files: top level build.gradle : . // Top-level build file where you can

Dagger: Inject @Named strings?

会有一股神秘感。 提交于 2019-11-26 17:13:41
问题 EDIT 2018-02-08: Sample project demonstrating how to do this at https://github.com/ravn/dagger2-named-string-inject-example - Note: the whole source is in a single file! I am looking at whether dagger can replace guice for us (as our deployment Java platform is slow). I construct a map of configuration strings at runtime, which I would like to have dagger inject as needed. E.g. If I have java.util.Map<String, String> map = new java.util.TreeMap<String, String>(); map.put("key", "value"); and

Looking for an example for Dagger assisted injection

青春壹個敷衍的年華 提交于 2019-11-26 16:34:07
问题 From dagger-discuss@: I have a class that gets some dependencies from the object graph, and other dependencies from a caller at runtime. public class ImageDownloader { // Get these dependencies from the injector. private final HttpClient httpClient; private final ExecutorService executorService; // Get these from the caller. private final URL imageUrl; private final ImageCallback callback; ... } I came up with a solution, where I define a Factory, public class ImageDownloader { ... public

Update to Kotlin 1.3.30 breaks build with Dagger 2.21

天涯浪子 提交于 2019-11-26 14:41:30
问题 Build error after update from Kotling 1.3.21 to 1.3.30: AppComponent.java:16: error: [Dagger/MissingBinding] java.util.Map<java.lang.Class<? extends androidx.lifecycle.ViewModel>, javax.inject.Provider<androidx.lifecycle.ViewModel>> cannot be provided without an @Provides-annotated method. Reproduced on two different projects with similar dependencies on Kotlin, Dagger and Architecture components. I suspect it somehow related to the recent kapt updates in kotlin 1.3.30: https://blog.jetbrains

How do you override a module/dependency in a unit test with Dagger 2.0?

穿精又带淫゛_ 提交于 2019-11-26 11:56:38
问题 I have a simple Android activity with a single dependency. I inject the dependency into the activity\'s onCreate like this: Dagger_HelloComponent.builder() .helloModule(new HelloModule(this)) .build() .initialize(this); In my ActivityUnitTestCase I want to override the dependency with a Mockito mock. I assume I need to use a test-specific module which provides the mock, but I can\'t figure out how to add this module to the object graph. In Dagger 1.x this is apparently done with something

Dagger 2 subcomponents vs component dependencies

独自空忆成欢 提交于 2019-11-26 08:39:59
问题 Dagger 1\'s plus() method is something I used quite often in previous applications, so I understand situations where you might want to have a subcomponent with full access to the parent graphs bindings. In what situation would it be beneficial to use a component dependency instead of a subcomponent dependency and why? 回答1: Component dependencies - Use this when you want to keep two components independent. Subcomponents - Use this when you want to keep two components coupled. I will use the

How to set up DAGGER dependency injection from scratch in Android project?

北城余情 提交于 2019-11-26 04:57:34
问题 How to use Dagger? How to configure Dagger to work in my Android project? I\'d like to use Dagger in my Android project, but I find it confusing. EDIT: Dagger2 is also out since 2015 04 15, and it\'s even more confusing! [This question is a \"stub\" on which I am adding to my answer as I learned more about Dagger1, and learn more about Dagger2. This question is more of a guide rather than a \"question\".] 回答1: Guide for Dagger 2.x (Revised Edition 6) : The steps are the following: 1.) add