dagger

Update to Kotlin 1.3.30 breaks build with Dagger 2.21

我们两清 提交于 2019-11-27 09:24:00
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.com/kotlin/2019/04/kotlin-1-3-30-released/ Tried to disable/enable the kapt options from the article,

Dagger- Should we create each component and module for each Activity/ Fragment

好久不见. 提交于 2019-11-27 08:58:18
问题 I've been working with dagger2 for a while. And I got confused wether to create an own component/module for each Activity/ Fragment. Please help me clarify this: For example, We have an app, and the app has about 50 screens. We will implement the code following the MVP pattern and Dagger2 for DI. Suppose that we have 50 activities and 50 presenters. In my opinion, usually we should organize the code like this : Create an AppComponent and AppModule which will provide all objects that will be

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

大憨熊 提交于 2019-11-27 06:20:35
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 like this : @Before public void setUp() { ObjectGraph.create(new TestModule()).inject(this); } What's the

How to use dagger in a android library project

你离开我真会死。 提交于 2019-11-27 05:21:19
问题 I'm currently trying to add Dagger to my android projects. For the apps projects its easy and clear to me, how to build the ObjectGraph. But I dont quite know whats the best way to do this in my android library projects. Should I keep building the ObjectGraph in the Application class of the apps and pass the OG over to a LibraryModule - plussing the OG of library to the Apps OG? Or should i build the whole ObjectGraph in the library? What if I need to inject a class in the library by

Can I extend a custom Application in Espresso?

时光毁灭记忆、已成空白 提交于 2019-11-27 02:32:22
问题 I'm attempting to set up Dagger in my Espresso instrumentation tests in order to mock out calls to external resources (RESTful services in this case). The pattern I followed in Robolectric for my unit testing was to extend my production Application class and override the Dagger modules with test modules which will return mocks. I'm attempting to do the same thing here, but I'm getting a ClassCastException in my Espresso tests when I try to cast the application to my custom application. Here

Dagger 2 on Android @Singleton annotated class not being injected

假如想象 提交于 2019-11-27 02:22:50
问题 I am currently trying to integrate Dagger 2 into an Android application. My project setup is as follows: library app (depends on library) In my library project I defined a class that I'll later inject into other classes that need it (Activities and regular classes) in the library as well as the app project. @Singleton public class MyManager{ @Inject public MyManager(){ //Do some initializing } } Now - for instance in my Fragments or Activities or regular classes I'd inject the above Singleton

LiveData is not updating its value after first call

老子叫甜甜 提交于 2019-11-27 01:50:57
问题 I have been beating my head against the wall and I cannot understand why this is happening. I am working with the new Architectural Components for Android and I am having problems updating a LiveData with a List of Objects. I have two spinners. When i change the option in the first one, The second one must have its content changed. But this last part is not happening. Can anyone help me? State.java @Entity(tableName = "states") public class State{ @PrimaryKey(autoGenerate = false) private int

Can I just inject super class when use dagger2 for dependency injection?

寵の児 提交于 2019-11-27 00:20:40
问题 I use Dagger2 for DI in my android application. I found that I have to write inject method for every class that uses @Inject field. Is there a way that I can just inject the parent class so that I don't have to call inject on every subclass? Take Activity for example. I have a BaseActivity that that every Activity extends from. Is there a way that I can just create an inject method in the component for BaseActivity and just call inject in BaseActivity's onCreate, and @inject fields in sub

Dagger 2 subcomponents vs component dependencies

╄→尐↘猪︶ㄣ 提交于 2019-11-26 23:27:30
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? Praveer Gupta 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 below example to explain Component dependencies and Subcomponents . Some points worth noticing

Dagger + Retrofit dynamic URL

假如想象 提交于 2019-11-26 21:05:16
问题 PROBLEM I need to call API from domains entered by USER and I need to edit my Retrofit singleton before the call accordingly to the inserted data. Is there a way to "reset" my singleton, forcing it to recreate? or Is there a way to update my baseUrl with my data (maybe in Interceptor?) just before call? CODE Singletons @Provides @Singleton Retrofit provideRetrofit(SharedPreferences prefs) { String apiUrl = "https://%1s%2s"; apiUrl = String.format(apiUrl, prefs.getString(ACCOUNT_SUBDOMAIN,