dagger-2

android getting NULL error on inject DI into class

帅比萌擦擦* 提交于 2019-12-02 13:06:20
I can make DI from some class to use in application such as Retrofit , Picasso . they can work fine when i use them on Activity but when i try to use some DI on other class i get NULL, for exmple this code work fine public class ActivityRegister extends BaseActivities { @Inject GithubService githubService; @Inject JobManager jobManager; @Override public void onCreate(@Nullable Bundle savedInstanceState) { ... repositoryCall = githubService.getAllRepositories(); ... } private void getRepositories() { repositoryCall.enqueue(new Callback<List<GithubRepo>>() { @Override public void onResponse(Call

Dagger AndroidInjector cannot be provided without an @Provides-annotated method

廉价感情. 提交于 2019-12-02 11:40:30
I've done my Android projects MainActivity by means of the MVP pattern. So in my MainPresenter I want to inject a dynamic String, which then shall populate a TextView for instance: class MyMainPresenter @Inject constructor(@StringForTextView dynamicString : String ) whereas the StringForTextView annotation qualifier is defined as: import javax.inject.Qualifier @Qualifier @MustBeDocumented @Retention(AnnotationRetention.RUNTIME) annotation class StringForTextView then I also have my Interface: interface DynamicString { @NonNull fun getDynamicString() : String } which is implemented as: data

Dagger2 - Project Rebuild Error - Field Injection - Android

假装没事ソ 提交于 2019-12-02 09:23:55
I have been trying to implement Dagger2. Problem: When I use constructor injection, it works fine but when I use field injection, it throws an Error like below: Error:(6, 48) error: cannot find symbol class DaggerApplicationComponent /home/moderator/Downloads/Maulik/Sample Codes/Made/Dagger2Demo/app/src/main/java/com/dagger2demo/dagger2demo/di/component/ApplicationComponent.java Error:(18, 10) error: com.dagger2demo.dagger2demo.mvp.HomePresenter cannot be provided without an @Inject constructor or from an @Provides- or @Produces-annotated method. This type supports members injection but cannot

Implementing a simple Dagger2 sample

孤街浪徒 提交于 2019-12-02 08:44:18
I'm new using Dagger2 (I always used Koin) and I'm trying to implement a simple sample but I don't really know what I'm missing. This is what I got so far. app.gradle : ext.daggerVersion = '2.23.2' implementation "com.google.dagger:dagger:$daggerVersion" implementation "com.google.dagger:dagger-android-support:$daggerVersion" kapt "com.google.dagger:dagger-android-processor:$daggerVersion" kapt "com.google.dagger:dagger-compiler:$daggerVersion" AppModule.kt : @Module class AppModule { @Provides @Singleton fun provideApplication(app: App): Application = app @Provides @Singleton fun

Dagger2 not resolving dependency all the way

寵の児 提交于 2019-12-02 07:44:48
I have a MainActivity which injects Presenter, presenter object injects interactor and interactor object injects APIHelper. All the providers of presenter, interactor and APIHelper are there in MainModule. @Module public class MainActivityModule { private final MainActivity activity; //Context context; public MainActivityModule (MainActivity activity) { this.activity = activity; } @Provides @Singleton public MainViewPresenter providesMainPresenter(){ return new MainPresenterImpl(activity); } @Provides @Singleton ListingInteractor providesInteractor( ){ return new ListingInteractorImpl(activity

How to Instantiate an object with dynamic members with Dagger2?

有些话、适合烂在心里 提交于 2019-12-02 03:37:44
I have a class which gets arguments in a constructor: public class Dependency{ Dependency(int number1, int number2, int number3, DependencyListener listener){} } each dependent class needs to path different arguments in order to instantiate a dependency. How should i define the module and the component that other classes could initiate it properly while transferring different values and passing 'this' as the listener? Also, How should i use the @Inject method in this case? Edit 1 @jeff-bowman I was thinking of using the following method: @Module public class DependencyModule { int first; int

How to provide Context with Dagger2

你离开我真会死。 提交于 2019-12-02 03:12:14
I am learning Android and I am following some guides for Retrofit2 with RxJava and Dagger2. Now I want to handle no internet connection case. I've found this answer , which seems to be elegant, but I do not understand how to apply it. I've got some NetworkModule , with OkHttpClient provider. I assume I need to create OkHttpClient.Builder with interceptor. So it should look something like this: ` @Provides @Singleton OkHttpClient provideOkHttpClient(Cache cache) { ConnectivityInterceptor ci = new ConnectivityInterceptor(networkObservable())); OkHttpClient.Builder.addInterceptor(ci) return

Dagger 2 singleton in multiple instances

你说的曾经没有我的故事 提交于 2019-12-01 19:55:23
I just tested out Dagger 2 and I am having some strange behaviour regarding the singleton annotation. I created some test code to show my problem. My Module: @Module public class App { @Provides @Singleton ThingA provideThingA(){ return new ConcreteThingA(); } } Interface of the thing I want in singleton: public interface ThingA { void showMyId(); } Implementation: public class ConcreteThingA implements ThingA { @Override public void showMyId() { System.out.println(this); } } Code that executes Dagger: public void doStuff() { ThingA thingA=DaggerThingAComponent.create().provideThingA(); ThingA

Dagger 2 singleton in multiple instances

核能气质少年 提交于 2019-12-01 19:43:47
问题 I just tested out Dagger 2 and I am having some strange behaviour regarding the singleton annotation. I created some test code to show my problem. My Module: @Module public class App { @Provides @Singleton ThingA provideThingA(){ return new ConcreteThingA(); } } Interface of the thing I want in singleton: public interface ThingA { void showMyId(); } Implementation: public class ConcreteThingA implements ThingA { @Override public void showMyId() { System.out.println(this); } } Code that

dagger2 error “android.app.Application cannot be provided without an @Inject constructor or from an @Provides-annotated method”

一个人想着一个人 提交于 2019-12-01 19:16:33
I'm trying to implement dagger2 in my project, but I'm faced with an error " android.app.Application cannot be provided without an @Inject constructor or from an @Provides-annotated method ". Here's my code: App.java package com.poppmedia.wallpaperautomaton; import android.app.Application; import com.poppmedia.wallpaperautomaton.di.DaggerAppComponent; import dagger.android.AndroidInjector; import dagger.android.DaggerApplication; /** * The Android {@link Application}. */ public class App extends DaggerApplication { @Override protected AndroidInjector<? extends DaggerApplication>