Questions tagged dagger-2

Explore the latest questions and answers asked by our top developers.

How to mock ViewModel

I tried to mock ViewModel that inside of Fragment. I would be very grateful for help or advice. My code below: ViewModel public class BenchmarkViewModel extends ViewModel { …. public BenchmarkViewModel(Benchmarks benchmark) { this.benchmark = benchmark; } … ViewModelFactory to create VMs using Benchmark interfaces’ implementations public class ViewModelFactory extends ViewModelProvider.NewInstanceFactory { @Inject @Named("ListBenchmark") Benchmarks […]

By Daniil Arteev
Categorized as android, dagger-2, java, mockito

Hilt – Dependency cycle crash

If I just use the AuthRepository class in a single UseCase it’s fine. However, if I try to use it in both AuthUseCase and RefreshTokenUseCase as in the example, I get an error. Any suggestions other than using Lazy<> ? Any help will be appreciated. – Error – error: [Dagger/DependencyCycle] Found a dependency cycle: […]

By enjektor0
Categorized as android, dagger-2, dagger-hilt, dependency-injection, kotlin

IntelliJ error: cannot find symbol @javax.annotation.Generated : Android Studio Arctic Fox : JAVA 11

I have checked these are the questions and its answers but not got solution. Question 1 (SO), Question 2 (SO), Question 3 (SO), Question 4 (GitHub) also Question 5 (SO) but not getting solution. I am using Android Studio Arctic Fox | 2020.3.1 and my project configurations are as below : Project level build.gradle file […]

By Shailesh
Categorized as android, annotations, dagger-2, intellij-idea, java-11

How getting fragments from feature-module?

Now implemented inject to fragment constroctor as here: In the project, we use the single activity which initializes the factory of fragments We are migrating to multi-modularity, when the feature-module was moved out, we encountered the following – if we getting the fragment factory of this module, then we will lose what was in […]

Jetpack compose data store keeps recomposing screen

I’m migrating from Shared preference to data store using jetpack compose. everything works fine (data is saved and can be retreated successfully). However, whenever a Data is retrieved, the composable keeps on recomposing endlessly. I’m using MVVM architecture and below is how I have implemented data store. Below is declared in my AppModule.kt App module […]

Dagger/MissingBinding error when creating a subcomponent

I am experimenting with Dagger subcomponents and got an error that I am having some difficulties understanding. So basically I have a Subcomponent and a Component. // FeatureComponent.kt, @Subcomponent @Scope annotation class Feature @Subcomponent(modules = [FeatureModule::class]) @Feature interface FeatureComponent { fun inject(loginActivity: LoginActivity) @Subcomponent.Builder interface Builder { fun build(): FeatureComponent } } @Module class FeatureModule […]

Categorized as android, dagger-2

Android Dagger 2 Injecting in Interceptor

I just got a problem to inject repository in the interceptor to get access token when its needed or rather expired. I just don’t understand where I did something wrong. I just didn’t find any example how to deal with interceptor and repository. Thinking about that double "Retrofit.Builder" maybe this is a problem. What do […]

By Mateusz G lowski
Categorized as android, dagger-2, dependency-injection, interceptor

not able to inject mock using Dagger

I am new to Dagger and Mockito. I am tring to use constructor defined in Dagger module in Unit test so the object is created with default values. This is the Module: @Module class AutoCloseCountDownTimerModule { @Provides @Singleton fun getAutoCloseCountDownTimer( userInteractionClient: UserInteractionClient, rxPositionManager: RxPositionManager ): AutoCloseCountDownTimer { return AutoCloseCountDownTimer(userInteractionClient, rxPositionManager, 15000, 45000) } This is […]

By KinderDev
Categorized as android, dagger-2, java, junit, mockito

how do I inject MainActivity context using dagger2 in java?

I am trying to inject the context of the MainActivity into a class I have. I looked at this but it doesn’t work for me and I get the following error: /home/muhammadmehdi/ALL_PROJECTS/memex/memex-app/app/src/main/java/com/memex/ error: cannot find symbol import com.memex.components.DaggerMainActivityComponent; ^ symbol: class DaggerMainActivityComponent location: package com.memex.component This is the code that I wrote in the onCreate […]

By Sarim Mehdi
Categorized as android, android-context, dagger-2, java

Android dependency injection based on convention rules

I have been looking around a lot to try and find a way to avoid having to map every single DI interface to a concrete class, but be able to do it convention based, like I years ago have been used to do in C# with Castle Windsor. If it is Hilt, Dagger2, Koin or […]

By Morten Holmgaard
Categorized as android, dagger-2, dagger-hilt, dependency-injection, koin
1 2 3 4 30

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us