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
0 answers

Assisted Injection using Dagger Hilt and Provides annotation

I'm using dagger hilt as a dependency injection framework in my project, however, I have this situation where I need to provide Retrofit instance. Normally I do it using the @Provides annotation. @Provides @Singleton fun…
Hamza Sharaf
  • 811
  • 9
  • 25
1
vote
1 answer

Can I omit type in generics? - Kotlin

If I have a following interface: interface BaseDataRemote { fun getData(params: Params? = null): Single } Would it be possible have implementation of this interface that does not take Params? To have effectively something…
leszekt80
  • 15
  • 3
1
vote
0 answers

Change Retrofit baseUrl with Dagger in runtime

Is there is some solutions to change Retrofit BaseUrl in runtime? I'm using Dagger to make Retrofit instance, but in my case Url is the users input after Application created and launcher activity started.
dbuzin
  • 195
  • 2
  • 13
1
vote
0 answers

Migrating from Dagger 2 to Hilt with TestApplication and custom test Component

I am migrating a quite extensive app with many instrumented tests in it. The way the app is structured is: // in the main sources open class MainApp { open val appComponent: ApplicationComponent = DaggerApplicationComponent.factory... } // in…
Alex Facciorusso
  • 2,290
  • 3
  • 21
  • 34
1
vote
1 answer

How to use Dagger for Groovy?

How to configure dagger to inject groovy classes, and to inject into groovy classes? I was initially trying to get dagger to inject a groovy class into my java app, and I found dagger was complaining the groovy class is not found. Looking at the…
Vin
  • 559
  • 2
  • 18
1
vote
1 answer

Hilt Singleton for Android Service - ended up with 2 instances

I am using Hilt for dependency injection, and I wanted to start a singleton Android Service (DeviceConnectionService), and be able to access that Service object to do something to it I observed 2 instances of DeviceConnectionService being created…
1
vote
1 answer

Module in Module Dagger: This module is public, but it includes non-public (or effectively non-public) modules

I am using Dagger 2 for DI and want to inject one Module (module A) inside another one (module B). I am not including module A in any component or anywhere else. My code looks like this: @Module public class ModuleA { @Provides @Singleton …
as2d3
  • 802
  • 2
  • 10
  • 27
1
vote
1 answer

Hilt - Field injection returning a null object refernece

This is my first time using Hilt for DI and I'm unsure what I'm doing incorrectly. I'm trying to Field inject my TestClass into my MainActivity, but it's giving me a null object reference when I call the method of the injected TestClass I've made…
DIRTY DAVE
  • 2,523
  • 2
  • 20
  • 83
1
vote
1 answer

Dagger multibinding java - for two or multiple implementation

I am trying to create a Dagger in Java code (not Android) for an Interface which has two or more implementations. I was able to do it successfully with CDI using javax libraries but I want to use Dagger this time around as per my project need. I am…
1
vote
1 answer

Hilt - inject classes as interfaces

Lets say I have two interfaces and two classes that implements them. interface ITest1 { fun doSomething() } interface ITest2 { fun doSomethingElse() } class Test1 @Inject constructor(): ITest1 { override fun doSomething() { …
Ivan Škugor
  • 558
  • 1
  • 6
  • 21
1
vote
1 answer

Dagger and Room, not creating DaggerTestAppComoponent.create()

I'm trying to run an end-to-end test on an app that uses Dagger and Room, When I run the app Dagger isn't able to generate DaggerTestAppComponent.create(). I've been following the Dagger codelab to implement the Dagger into the tests. Here's a link…
Shawn
  • 1,222
  • 1
  • 18
  • 41
1
vote
1 answer

Dagger Error: "The @AssistedFactory-annotated type should contain a single abstract, non-default method but found multiple"

I'm learning to use Dagger and assisted injection, and I have the following factory interface @AssistedFactory public interface IFactory{ HandlerA createHandlerA (String path); HandlerB createHandlerB (String path); HandlerC createHandlerC…
babajaj
  • 168
  • 1
  • 2
  • 11
1
vote
1 answer

Runtime value injection in Dagger vs. Guice

I'm migrating a project from Guice to Dagger, and I'm trying to understand what to do with injection of values at runtime. Let's say I have a Guice module with the following configure method: void configure() { install(new…
babajaj
  • 168
  • 1
  • 2
  • 11
1
vote
1 answer

Android Dagger - Dynamic feature module can't inject from AppComponent

In :app module @Singleton @Component(modules = [AppModule::class]) interface AppComponent { @Component.Factory interface Factory { fun create(@BindsInstance context: Context): AppComponent } } @Module class AppModule { …
PhongBM
  • 799
  • 10
  • 23
1
vote
1 answer

@Component.Builder is missing setters for required modules or components: [com.sample.TestComponent]

There are many answers in SO regarding the above question, however my case is different, for me the setters for component is missing. I have ApplicationComponent which depends on some other component [TestComponent] coming from a…
AndroidDev
  • 1,485
  • 2
  • 18
  • 33