dagger

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

不想你离开。 提交于 2019-11-28 04:19:43
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 activities get injected automatically? Kirill Boyarshinov It cannot be done right now. Explanation by

Difference between Dagger and ButterKnife Android

☆樱花仙子☆ 提交于 2019-11-28 03:14:55
Can anyone point out the difference between Dagger and Butterknife ? I know that Butterknife is a view injection library and Dagger is a dependency injection library. But the documentation online seems a bit overhead for me. According to Butterknife documentation, you can do non-activity injections as well, which is what Dagger does? Or did I misunderstand something? ButterKnife is targeted to inject views only. Non-activity injection just means that you can provide your own view root to inject views from (like with manually inflated views, etc.). Dagger is a bit more complicated. It can

How to migrate missing inject from module with complete = false from Dagger 1 to Dagger 2

白昼怎懂夜的黑 提交于 2019-11-28 01:42:30
问题 I have a library project/module that is used by both Android apps and regular java apps. In Dagger 1 this project/module has property complete = false . Within there is an @Inject field that is not satisfied by any class implementation or @Provides method. The idea is to force the "top" module(s) which has complete = true to provide system specific implementation Just for the sake of example: In the library project I have ActLogin activity that have field @Inject @Named("app version")

Can't locate import javax.inject.Inject package

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 23:03:15
问题 I'm trying to implement Dagger as a dependency injector in an IntelliJ project, but my code is failing on: import javax.inject.Inject; Intellij is finding the ' javax ' package, but not the ' inject ' package, so it fails. I am new to Android, so I apologize if this is a no brainer, but can anyone tell me why the inject package is not being found? 回答1: Dagger depends on JSR 330, the Java standard annotations which are used for dependency injection (think: @Inject , @Singleton , etc.). This is

Dagger + Retrofit dynamic URL

杀马特。学长 韩版系。学妹 提交于 2019-11-27 22:27:48
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, null), prefs.getString(ACCOUNT_DOMAIN, null)); OkHttpClient httpClient = new OkHttpClient.Builder()

Looking for an example for Dagger assisted injection

帅比萌擦擦* 提交于 2019-11-27 21:17:24
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 static class Factory { private final HttpClient httpClient; private final ExecutorService executorService

Specifying order of annotation processors

一个人想着一个人 提交于 2019-11-27 20:06:24
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 & mvn compile is enough to demonstrate the issue - if you comment line 18 and uncomment lines 20-21 in App

Dagger: IllegalArgumentException: No injector factory bound for Class

你。 提交于 2019-11-27 17:05:08
问题 I am new to Dagger 2. I have 2 Activities, I want to use injected ViewModel for both. Here is my ViewModuleFactory : @Singleton public class ProductViewModelFactory implements ViewModelProvider.Factory { private final Map<Class<? extends ViewModel>, Provider<ViewModel>> creators; @Inject public ProductViewModelFactory(Map<Class<? extends ViewModel>, Provider<ViewModel>> creators) { this.creators = creators; } @SuppressWarnings("unchecked") @Override public <T extends ViewModel> T create(Class

Refreshing Dagger 2 instance from Android Application class

。_饼干妹妹 提交于 2019-11-27 16:11:44
问题 I have a set of @Singleton and @Provides method in my module class for the purpose of creating Singleton instance throughout the application. Everything works fine except few bottle neck scenarios like as follows: STEP 1. I am creating a Retrofit instance from OKHttpClient with Auth token in it to make a authenticated api calls each time (Auth token retrieval and insertion is handled through SharedPreferences ). But the problem starts at the time of relaunching the activity after when i

Dagger: Inject @Named strings?

∥☆過路亽.° 提交于 2019-11-27 16:00:18
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 @Inject Thermosiphon(Heater heater, @Named("key") String value) { this.heater = heater; System.out