dagger

Singletons in Dagger 1.x

余生长醉 提交于 2019-11-28 23:16:14
When using Dagger, I found that I'm getting multiple instances of a singleton when I inject it wherever I need it. I've annotated the class and the provides method with @Singleton . Can anyone think of why this is happening? Edit: If it helps, I have followed the same structure for my app as the sample application in Dagger's GitHub ( https://github.com/square/dagger/tree/master/examples/android-activity-graphs ). I'm trying to get the Singleton in the base activity and a couple of third party classes provided using @Provides at the custom Application class. Is it because I'm plus-ing modules

Dagger example built through eclipse fails with 'Please ensure that code generation was run for this module.'

拥有回忆 提交于 2019-11-28 21:27:52
I'm using Dagger for dependency injection in Android, using Eclipse to build. I've cloned android-activity-graphs to use as an example. I've set up my environment according to staxgr from https://github.com/square/dagger/issues/126 These are my libs: dagger-1.1.0.jar , dagger-compiler-1.1.0.jar , and javax.inject.jar And lastly, I've changed the source folders in Eclipse to point to src/main/java (instead of just src/ ) so that Eclipse detects the related files through the package keyword. The project builds, but fails immediately when it's run with this exception: Caused by: java.lang

How do I use AndroidInjection class in custom views or other android classes?

女生的网名这么多〃 提交于 2019-11-28 20:29:43
My issue with the Android-specific pattern is, if you use their AndroidInjection class, there is no way to members inject other objects besides Activities / Fragments /custom views/adapters, except with the Application Component. This is because you cannot get a reference the the Subcomponent ( AndroidInjector ) used to inject Activities / Fragments . This makes injecting Dialogs (if you use DialogFragments ). The AndroidInjection class seems to support just the core Android types. What follows is not an answer to your question, but an explanation why you shouldn't be asking this question at

Dagger + Retrofit. Adding auth headers at runtime

拈花ヽ惹草 提交于 2019-11-28 17:07:04
问题 I'm wondering if there is a way for Dagger to know that it should recreate an object when new data is available. The instance I am speaking of is with the request headers I have for retrofit. At some point (when the user logs in) I get a token that I need to add to the headers of retrofit to make authenticated requests. The issue is, I'm left with the same unauthenticated version of retrofit. Here's my injection code: @Provides @Singleton OkHttpClient provideOkHttpClient(Cache cache) {

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

让人想犯罪 __ 提交于 2019-11-28 15:03:43
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 used while the app is open. @Module public class AppModule { private final MyApplicationClass

Can I use some kind of assisted Inject with Dagger?

帅比萌擦擦* 提交于 2019-11-28 14:16:19
With Google Guice or Gin I can specify parameter with are not controlled by the dependency injection framework: class SomeEditor { @Inject public SomeEditor(SomeClassA a, @Assisted("stage") SomeClassB b) { } } The assisted parameter stage is specified at the time an instance of SomeEditor is created. The instance of SomeClassA is taken from the object graph and the instance of SomeClassB is taken from the caller at runtime. Is there a similar way of doing this in Dagger? Because factories are a separate type of boilerplate to optimize away ( see mailing list discussion here ), Dagger leaves it

LiveData is not updating its value after first call

自古美人都是妖i 提交于 2019-11-28 07:37:20
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 id; private String name; @ColumnInfo(name = "countryId") private String CountryId; @Ignore private

What are the specific benefits of using DI on Android?

时间秒杀一切 提交于 2019-11-28 07:26:59
What are the specific benefits or advantages of using a dependency injection framework for Android, like Dagger , Transfuse or RoboGuice ? For example, what kind of apps would benefit the most from using DI? is there more of a performance advantage, or is it more on the ease of extending an app, or even more about making it testable? One of the reasons for asking this is to gauge if an app I'm developing would actually benefit from it or not much. Since I intend the app to be serious at some point, testability and ease of extension would be great, even if costly to use (more time to setup,

Dagger + Proguard obfuscation, Errors creating object graph

你说的曾经没有我的故事 提交于 2019-11-28 05:49:56
问题 Running an obfuscated version of my application throws the following stacktrace java.lang.RuntimeException: Unable to create service com.mycompany.myapp.async.alarms.AlarmIntentService: java.lang.IllegalStateException: Errors creating object graph: dagger.Lazy could not be bound with key dagger.Lazy required by dagger.Lazy com.mycompany.scheduler.c.mNotificationDisplayer If I add -dontobfuscate, it runs smoothly Here's the class that contains that field public abstract class

How to use dagger in a android library project

久未见 提交于 2019-11-28 04:28:40
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 ObjectGraph.inject(this) ? In my Apps projects I can get the OG from the Application class. But how to handle