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
14
votes
1 answer

How to work with DaggerApplication and DaggerAppCompatActivity

I'm trying to get my head around the new Dagger2 APIs and support for Android. I'm using Dagger2 version 2.15: implementation 'com.google.dagger:dagger:2.15' implementation 'com.google.dagger:dagger-android:2.15' implementation…
Reza Bigdeli
  • 1,142
  • 1
  • 12
  • 25
14
votes
2 answers

java.lang.IllegalArgumentException: No injector factory bound for Class

The error I have is following: Caused by: java.lang.IllegalArgumentException: No injector factory bound for Class. Injector factories were bound for supertypes of MyActivity_: [MyActivity]. Did you mean to bind an injector factory for the…
aleksandrbel
  • 1,422
  • 3
  • 20
  • 38
14
votes
2 answers

Finding actual error out of data binding error

I am using data binding without any problems and it works good. But sometimes it frustrate me a lot by hiding the real problem by showing data binding error for no reason. Last time i made some changes in room database and mistakenly used wrong…
jatin rana
  • 825
  • 1
  • 9
  • 21
14
votes
1 answer

Dagger 2.11 - A binding with matching key exists in component

I have a small scenario where I have this following structure where I'm trying to inject fragment manager in baseActivity Fragment but for some reason I'm running out of luck :( @Singleton @Component(modules = { AppModule.class, …
user3354265
  • 777
  • 1
  • 10
  • 26
14
votes
4 answers

Espresso, Dagger2 set ViemodelProvider.Factory on BaseActivity

I have an abstract AccountRequiredActivity that looks like this (and works fine): public abstract class AccountRequiredActivity extends LifecycleActivity { @Inject ViewModelProvider.Factory viewModelFactory; private AccountViewModel…
html_programmer
  • 18,126
  • 18
  • 85
  • 158
14
votes
2 answers

Dagger 2 on Android. Different ways to store and access a @Singleton Component

This is the Nth question about how to store @Singleton scoped Dagger 2 Components whose lifetime should equal the application's lifetime. In Android apps using Dagger 2 there is usually at least one Component which is @Singleton scoped and should…
Marco Romano
  • 1,169
  • 7
  • 24
14
votes
1 answer

Context cannot be provided without an @Provides-annotated method, but it is?

I have the following simple module: @Module public class ApplicationModule { private CustomApplication customApplication; public ApplicationModule(CustomApplication customApplication) { this.customApplication = customApplication; …
Eduardo Naveda
  • 1,880
  • 3
  • 15
  • 30
14
votes
2 answers

Dagger2 Component (un-scoped) cannot depend on scoped components - Error

I am trying to compile https://github.com/svenjacobs/android-dagger2-example but I am running into an error related to unscoped component depending on scoped components. (Android Studio 1.1, Gradle 2.2.1). Also if anyone knows of other Dagger2…
Get Smarter
  • 181
  • 2
  • 2
  • 9
14
votes
2 answers

Gradle: force use of a repository for a dependency

I would like to know if there is a way to force gradle to use a repository for one dependency. For instance with: buildscript { repositories { jcenter() mavenCentral() maven { url 'https://www.testfairy.com/maven' } maven { url…
E-Kami
  • 2,529
  • 5
  • 30
  • 50
13
votes
5 answers

Provide Activity instance with Hilt

How can I translate something like this: @Module abstract class BaseActivityModule { @Binds abstract fun provideActivity(activity: A): AppCompatActivity companion object { @Provides …
GuilhE
  • 11,591
  • 16
  • 75
  • 116
13
votes
3 answers

Generated Files (Dagger, LiveData) show up on the wrong branch and get regenerated if I delete them

This happens for both Dagger generated files and for LiveData generated binding files. I'll change branches and the generated file for the new Live Data layout or the generated MemberInjector for a new daggeer component will stick around even…
Dan Anderson
  • 1,062
  • 13
  • 26
13
votes
2 answers

How to inject Mocked Presenter of Activity in Instrumentation testing with Espresso

I have been trying this for a week. And I have crawled every article available but their implementations or examples fall short or stop at the steps of Espresso Tests. My Android Application follows MVP architecture (And is in Java) Scenario:…
yUdoDis
  • 1,098
  • 6
  • 15
13
votes
3 answers

Android dagger cannot be provided without an Provides-annotated method

I decided to learn dagger dependency injection framework. After some tutorials I try to implement dagger into my project. However I got this error com\assigment\di\component\AppComponent.java:11: error: [Dagger/MissingBinding]…
David
  • 3,055
  • 4
  • 30
  • 73
13
votes
2 answers

lateinit property viewModelFactory has not been initialized in Fragment

I am using dagger 2 (version 2.15) for dependency injection in my android project. Everything works fine except injecting viewModelFactory. I cannot inject it in my fragment. @Inject lateinit var viewModelFactory: ViewModelProvider.Factory private…
Ana Koridze
  • 1,532
  • 2
  • 18
  • 28
13
votes
1 answer

Purpose of proxyProvide in Dagger 2 generated code

I have this Dagger module. I want to understand the generated code so I can verify that my Dagger configuration is optimal. @Module public class TypefaceModule { @Provides @Singleton @Named("Roboto Light") static Typeface…
Graham Borland
  • 60,055
  • 21
  • 138
  • 179