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

Dagger2 nullable injection

I'm trying to inject Glide with Dagger. So I have AppModule: @Module class AppModule { @Provides fun provideRequestOptions(): RequestOptions { return RequestOptions() .placeholder(R.drawable.white_background) …
faritowich
  • 67
  • 1
  • 10
1
vote
1 answer

Dagger 2 inject subcomponent.builder

I'm seeing some code where a SubComponent.Builder is being injected. For instance: class MyClass @Inject constructor(val mySubcomponentBuilder: MySubComponent.Builder) { fun someFunc(knownAtRuntime: String) { …
VIN
  • 6,385
  • 7
  • 38
  • 77
1
vote
1 answer

How to inject FirebaseMessagingService in Dagger 2?

I want to inject a class into a Service that extends FirebaseMessagingService but as far as I know, in order to inject stuff in a Service class that service should extends DaggerService(). This is what I tried @Singleton @Component( modules = [ …
1
vote
1 answer

Can not Binds Dependency with parameter in contructor with Dagger and Kotlin

I have some class that looks like as below: But I have an issue, I cannot provide dependency for HomeRouter. So can you guys help me solve this problem: class HomeRouter @Inject constructor (activity: Activity) : HomeContract.Router { override…
Thang
  • 409
  • 1
  • 6
  • 17
1
vote
1 answer

Android + Kotlin + Hilt: Cannot @Inject in a non activity class

I recently started learning Hilt, and for now it's giving me more headaches than happiness, but I like challenges, so let's go to the point. I'm having plenty of problems understanding how to inject in non activity classes, for example to inject a…
Diego Perez
  • 2,188
  • 2
  • 30
  • 58
1
vote
0 answers

Does Dagger support multibinding with KClass<*> type?

I have a KeyMap like this: @Target(AnnotationTarget.FUNCTION) @MapKey annotation class JsonSerializerKey(val value: KClass<*>) and want to provide them as: // #1 doesn't work Map, @JvmSuppressWildcards KSerializer<*>> // #2…
beigirad
  • 4,986
  • 2
  • 29
  • 52
1
vote
0 answers

How to Inject constructor to abstract class with Dagger2

I have an abstract ViewModel abstract class AbstractViewModel( protected val dataStore: dataStore, protected val schedulerProvider: SchedulerProvider ): ViewModel() { abstract fun doSomething() } that is inherited by many…
Mehdi Satei
  • 1,225
  • 9
  • 26
1
vote
3 answers

Cannot find DaggerAppComponent inside Application class

I'm using kotlin latest version and trying to implement dagger2, but after rebuilding the project the suggestions would never give me "DaggerAppComponent" to build. my dependencies implementation 'com.google.dagger:dagger:2.38.1' implementation…
Ashana.Jackol
  • 3,064
  • 28
  • 22
1
vote
1 answer

Equivalent of @componentScan in dagger?

Sorry for this basic question I am asking but can someone tell me if dagger dependency injection can work just with @module, @provides @Inject etc. That is without using @component annotation? In spring DI, we use @componentScan to let spring know…
Akash Chauhan
  • 232
  • 1
  • 8
1
vote
0 answers

Dagger - Dependency inject into Activity

I have a main activity as below: @AndroidEntryPoint class MainActivity : BaseActivity() { @Inject lateinit var configuration: Configuration ... } And a module defined like: @Module @InstallIn(SingletonComponent::class) class AppModules { …
KTOV
  • 559
  • 3
  • 14
  • 39
1
vote
1 answer

Dagger2 Can't provide dependency of activity to dagger

MainActivity cannot be provided without an @Inject constructor or an @Provides-annotated method. This type supports members injection but cannot be implicitly provided. I'm using dagger-android, I injected MainActivity through…
qarasique
  • 173
  • 1
  • 8
1
vote
0 answers

Dagger 2 with ViewModel provided at module

Almost all tutorial or article that I read always instantiate ViewModel in Activity or Fragment class, however is it okay to create a module to provide ViewModel thus instantiation can be skipped? Using the popular solution for Dagger 2 and…
1
vote
1 answer

Hilt provide dependency after making a network call

I need to provide a graph client for Storefront API but I can only build the client after making a network call. @Provides @Singleton fun getGraphClient(context: Context, client: Client): GraphClient { return GraphClient.build( context =…
Akram Hussain
  • 472
  • 8
  • 23
1
vote
1 answer

Dagger @Inject and @AssistedInject together

The goal is to inject a class with an optional constructor parameter. If using @Inject the class will be created without the optional parameter, while if I want to pass the optional parameter I can use a factory @AssistedFactory. I am trying to…
1
vote
1 answer

Dagger: How to check if dagger.Lazy variable has been initialised

I found the answer for Kotlin Lazy objects, using isInitialized() here: Kotlin: Check if lazy val has been initialised But seems like dagger.Lazy doesn't have the same public method. This is how I lazily inject using Dagger: @Inject internal…
Bruce
  • 2,357
  • 5
  • 29
  • 50