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

How get viewModelScope from hilt

My Paging class class UserDataSource @Inject constructor(private val listService: ListService, private val scope: CoroutineScope): PageKeyedDataSource() I need get viewModelScope from ViewModel, but I always get error when try and…
Svetl9chok
  • 153
  • 5
1
vote
1 answer

Dagger fails to recognize the provider implementation

I have a list of enum that I need to inject to view model via constructor but dagger fails with this error SelectDisabilityComponent.java:7: error: [Dagger/MissingBinding] java.util.List cannot be provided without…
user2934930
  • 1,076
  • 2
  • 12
  • 26
1
vote
1 answer

Dagger Hilt - What’s the point of @ApplicationContext and @ActivityContext?

In regards to @ApplicationContext and @ActivityContext in Hilt, I understand that they help to resolve ambiguity when a Context is being requested… but why not just request Application or Activity directly?
rpg
  • 23
  • 2
1
vote
1 answer

Hilt : @DefineComponent dagger.hilt.components.SingletonComponent is missing a parent declaration

I am setting up a project using Jetpack Compose + Hilt + Coroutines. I haven't used any fragment. It is a single activity(ComponentActivity) based project. I have used the latest versions : Kotlin : 1.4.31 & Hilt : 2.33-beta This is the logcat…
1
vote
1 answer

Can I get the context inside ViewModel's init block?

I am implementing offline mode for my application, my plan is to put the local db between the UI and API Requests. I have this fragment and his viewmodel with this init block: init { viewModelScope.launch(Dispatchers.IO) { // context…
SKREFI
  • 177
  • 2
  • 13
1
vote
1 answer

How does Dagger2's built-in AssistedInject support factories that return interfaces instead of classes

I'm poking around with Dagger2 and its built-in AssisedInject annotation. The tutorial available at dagger.dev shows an example where the factory method returns a concrete class but I would have expected the factory to return an interface for which…
David
  • 11
  • 2
1
vote
2 answers

class file for androidx.room.RoomDatabase not found when trying to use Hilt with Roomdb

This is the error message I am getting. I checked the web and I have every dependency needed, I setup everything correctly. The problem is that I already have this setup on another project which is working fine, for some reason tho it's not working…
1
vote
1 answer

No injector factory bound for Class

I have created a tab layout(WorkoutAtHome and Workoutinstudio) inside the HomeFragment and to create tab layout obviously i have used fragment. Now i want to inject ViewModelProviderFactory object inside the tablayout fragments. so for that what I…
Rahul Yadav
  • 161
  • 3
  • 11
1
vote
1 answer

How should ActivityRetainedLifecycle.OnClearedListener be used?

I'm injecting an @ActivityRetainedScoped component via Hilt. The component is registering a listener so I want to make sure it cleans up after itself and doesn't leak anything. I have seen ActivityRetainedLifecycle.OnClearedListener in the JavaDocs…
anotherdave
  • 6,656
  • 4
  • 34
  • 65
1
vote
1 answer

Dagger2 - Best practice for passing an Object to a Module?

I'm trying to create a RetrofitModule. I have an interceptor that adds dynamic headers using a AuthHeader object. I'm unsure how I can pass this object to the module class. @Module public class RetrofitModule { private static final String TAG =…
DIRTY DAVE
  • 2,523
  • 2
  • 20
  • 83
1
vote
0 answers

Fragment generic view model in dagger 2

I am trying to make a CustomBaseFragment that receives a base View Model and then initializes it and performs the providers based on the view model that is being passed in raw. I also created a TestFragment that inherits the CustomBaseFragment and…
1
vote
1 answer

Dagger 2 Singleton between Android Activities

I am trying to understand how @Singleton works on Dagger 2 build.gradle implementation 'com.google.dagger:dagger:2.32' kapt 'com.google.dagger:dagger-compiler:2.32' Vehicle.kt @Singleton class Vehicle @Inject constructor() { var speed =…
Dino Tw
  • 3,167
  • 4
  • 34
  • 48
1
vote
0 answers

How to get Dagger2 class property in extension function?

I'm using Dagger2, and would like to use my app's version string in an extension function for a third party class. The app exposes the version as so currently: BuildConfigProvider.kt interface BuildConfigProvider { val version:…
user1114
  • 1,071
  • 2
  • 15
  • 33
1
vote
1 answer

Unable to Inject ViewModel from a different module in Android project

I am not sure if this is a limitation of the Dagger Hilt library, but i seem to be unable to inject a ViewModel from a different module in activity. Project: :modA (OrderViewModel with @HiltViewModel annotation) :modUI (DI stuff here that…
Otieno Rowland
  • 2,182
  • 1
  • 26
  • 34
1
vote
1 answer

How to skip autogenerated classes from Javadoc using gradle

In an Android library project I use Gradle script to generate Javadocs: task androidJavadocs(type: Exec, dependsOn: buildJavadocsClasspath) { doFirst { executable = 'javadoc' args = [ '-classpath', javadocsClasspath, …
LR89
  • 397
  • 1
  • 4
  • 14