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

Android using Dagger2 with multiple project modules

I have two project modules (with this I mean two android modules with their own gradle, manifest, etc.. Not the Dagger module). I call them MyAppCore and MyApp. MyAppCore has the logic around the database access and network access. MyApp has all the…
IIRed-DeathII
  • 1,117
  • 2
  • 15
  • 34
1
vote
2 answers

Is there a way to access Guice injectors which have previously been created?

Taking a look at Guice (and Dagger) for a new project. Every Guice tutorial I have seen so far shows an injector being created at the point where the developer needs the DI to create an object instance. A typical example seen on the web: public…
Peter
  • 5,455
  • 7
  • 46
  • 68
1
vote
2 answers

Starting Dagger2, How to construct structure?

I am studying Dagger2 now. I am studying by looking at several examples. But there are some parts that aren't working properly, looking at the examples. I know that the structure of Dagger2 should be defined and implemented in the order of…
jakchang
  • 402
  • 5
  • 13
1
vote
1 answer

Injecting a stateful repository into a WorkManager Worker

This is mostly an app architecture question. I have a repository class that centralizes operations on collections of media: interface MediaRepository { suspend fun getTracks(): List suspend fun getAlbums(): List fun…
1
vote
1 answer

Inject retrofit android kotlin

ApiModule.kt @Module class ApiModule { @Provides @Singleton fun provideRetrofit(): Retrofit { return Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create()) …
Hardik Bambhania
  • 1,732
  • 15
  • 25
1
vote
2 answers

Dagger and Butterknife

I am using dagger2 in my app. But when I started project my activities was extended support AppcompatActivity.Now while build I am getting warning via butterknife. API 'variantOutput.getProcessResources()' is obsolete and has been replaced with…
1
vote
1 answer

Re-initialization an object provided by Dagger 2

I have an interface called LoginService which is used with Retrofit. There was no accessToken before the user login. When the user has logged in, the LoginService Instance should be updated with acessToken so that the user could log out from the…
Daniel Jr McCoy
  • 157
  • 1
  • 15
1
vote
1 answer

What is the use of DSL in Koin?

In dagger 2, we had code generation at compile time. According to the Koin library website, Koin doesn't do any code generation and is a "DSL, a lightweight container and a pragmatic API". After reading Martin Fowlers Blog regarding DSL, It appears…
Richard Miller
  • 576
  • 1
  • 7
  • 18
1
vote
1 answer

java.lang.RuntimeException: Failed to invoke public io.reactivex.Observable() with no args

Hello, I am currently preparing one simple demo example of MVVM with Coroutines and I am facing the below issue. Please have a look into the code and what wrong with the code. E/AndroidRuntime: FATAL EXCEPTION: main Process:…
Maulik Sinroja
  • 191
  • 1
  • 6
  • 17
1
vote
1 answer

lateinit property apiComponent has not been initialized in Dagger 2

I'm trying to implement Dragger 2 in recyclerview but I'm getting following error when running the app: kotlin.UninitializedPropertyAccessException: lateinit property apiComponent has not been initialized at…
GK007
  • 117
  • 2
  • 15
1
vote
0 answers

How to use injected depencies inside an instrumentation test

I set up my instrumentation tests to use the appropriate test app dependencies using dagger. My TestApplicationComponent @Component(modules = [ (AndroidInjectionModule::class), (TestApplicationModule::class), …
1
vote
2 answers

Cannot inject interface in kotlin dagger2 mvvm

hi i am using mvvm and dagger2 when i try to inject my Doa interface in the following class @Singleton class PodCastRepository @Inject constructor(private val dao: PodCastDao) { } my interface class interface PodCastDao { fun getLegoThemes():…
1
vote
1 answer

Provide singleton dependency vs object initialization

I have two questions about Dagger2 and it's Singleton scope, I used Retrofit and GSON but it's just for the example, I want to make sure I understand Dagger2 correctly. I have NetowrkModule like: @Module public class NetworkModule { @Provides …
sharonooo
  • 684
  • 3
  • 8
  • 25
1
vote
0 answers

How to inject a dynamic feature to a module in android?

I'm new to android and now I'm currently working on a project which asks me to split some dynamic features from an Android app. I followed the guide on the Internet, but when I try to run my code, it shows the following error message: Caused…
earthaa
  • 11
  • 2
1
vote
2 answers

How to provide GoogleSignInOptions using Dagger2?

I am trying to make small Firebase login app using Dagger2, but I have a problem with GoogleSignInOptions. I want to set it in the AppModule, but .requestIdToken have an error with: (getString(R.string.default_web_client_id)) Is my approach with…
beginner992
  • 659
  • 1
  • 9
  • 28