Questions tagged [dagger-2]

Dagger 2 is a dependency injection framework for Java and Android. It implements the full stack with generated code

Dagger 2 is a compile-time dependency injection framework for and .

It uses code generation and compile-time validation taking the approach started with Dagger 1 to it's ultimate conclusion. Dagger 2 eliminates all reflection and improves code clarity by removing the traditional ObjectGraph/Injector in favor of user-specified @Component interfaces. Dagger 2 implements the full stack with generated code.

Useful Links

3161 questions
1
vote
1 answer

@Inject in BaseActivity

I am following coding with mitch's dagger 2 course from youtube.I am confused about something.Here is my classes: AppComponent.class @Singleton @Component( modules = { AndroidSupportInjectionModule.class, …
Jarnojr
  • 543
  • 1
  • 7
  • 18
1
vote
1 answer

How to use AssistedInject to pass dynamic value as a parameter to ViewModel when using Dagger2 in Android

I am new to Dagger 2 in android. I am having trouble understanding how to inject ViewModel with dynamic value. So Far I have successfully injected ViewModel using dagger multi binding with pre-defined repository dependency. Here's my…
1
vote
0 answers

Java Lang NoSuchFieldError Releaseable References Manager

I'm trying to implement Scabbard to my project which is visualize dagger dependencies. I've followed the steps of its home page. but when I tried to build the project, it fails as shown below. I'll also add part of my Gradle. Actually, when I add…
1
vote
0 answers

Can't find Dagger2 module @Provides annotated methods when included in subcomponent

My app has a library (Core Library) we maintain as a module in the project and we include as a gradle dependency like this: build.gradle dependencies { api project(':core') } I'm trying to integrate this Core Library as a Dagger subcomponent…
kriztho
  • 300
  • 2
  • 14
1
vote
0 answers

Gradle annotation processor order (Android)

I'm writing a library based on code generation. This library generating dagger's module via annotations. How do I run my annotation processor before dagger's code generation? Now it crashes on build because dagger trying to build the component…
syncended
  • 81
  • 1
  • 7
1
vote
1 answer

Oauth2 refresh with Dagger2 Android

I'm trying to implement Oauth2 login with Dagger2. Once the access_token gets expired, I have successfully generated new access_token through the refresh_token, but the Authenticator goes on infinite loop once refresh_token is also expired. This is…
Aan
  • 289
  • 5
  • 15
1
vote
0 answers

Android: how to make multi-module dagger component injection?

I have android gradle multi-module dagger application. Inside each module I'm doing inject via it's own component like this: MainApp.appComponent.inject(this) for module :app and BaseApp.appComponent.inject(this) for module :app:base. Now trying to…
white-imp
  • 313
  • 2
  • 16
1
vote
1 answer

Dagger 2 NPE when trying to make member injection of interface type

I have problem with member injecting interface type. Here is example: I have interface let's call it BookActivity interface BookActivity {} it's simple marker interface that do nothing. and I have two implementation: BookNewActivity: Activity,…
d.popovych
  • 359
  • 1
  • 3
  • 9
1
vote
1 answer

how to handle dependency cycle dagger 2

I have two classes PdfTicketStorage and OfflineHelper they both depend on each other. OfflineHelper class requires PdfTicketStorage to send data to firebase class OfflineHelper @Inject constructor( private val app: App, private val settings:…
BRDroid
  • 3,920
  • 8
  • 65
  • 143
1
vote
0 answers

dagger2 inject generic interface

I want to inject an object of a generic interface type into another object class InjectionTarget { @Inject IGenericType object; } interface IGenericType { void foo(A a); void bar(B b); } class GenericTypeImpl
Piotr Śmietana
  • 393
  • 2
  • 19
1
vote
1 answer

UninitializedPropertyAccessException using Hilt

@Module @InstallIn(ApplicationComponent::class) object AppDataModule { @Provides @Singleton fun provideAU(loginPreferences: LoginPreferences, @ApplicationContext context: Context): AccountUtil = AccountUtil (loginPreferences,…
Arun
  • 510
  • 1
  • 4
  • 21
1
vote
2 answers

Android How to dependency inject variables into non activity?

I have an android application and I would like to perform dependency injection on a class which is not activity or fragment therefore the applicationContext is not present. @HiltAndroidApp class App: Application { @Inject lateinit var analytics:…
1
vote
1 answer

Android How to Inject application into class where context is not present?

I have an android application @HiltAndroidApp class MyApp extends Application { static MyApp app; static MyApp getApp() { return app; } @Override public void onCreate() { super.onCreate(); app = this; …
ashley
  • 181
  • 1
  • 8
1
vote
1 answer

How can I use Hilt to inject Retrofit to Repository, which is injected to ViewModel?

I have just learnt manual dependency injection, but I am trying out Hilt to handle these dependency injections. I want to inject a ViewModel into a Fragment. The fragment is contained within an Activity. Right now, I have added the annotations to…
Richard
  • 7,037
  • 2
  • 23
  • 76
1
vote
2 answers

Using Hilt @IntallIn for a dagger-2 module which has static provides method

While doing a dagger-2 to hilt migration, got this error for a module Error: FooModule.Companion is listed as a module, but it is a companion object class. Add @Module to the enclosing class and reference that instead. Before…
ullas_jain
  • 13
  • 8