dagger-2

HasActivityInjector can not be resolved in android dagger 2

落花浮王杯 提交于 2020-06-24 20:53:10
问题 I was trying to implement HasActivityInjector in my android application but it's showing me HasActivityInjector cann't be resolved. Below dependencies and plugin I have used in my project- apply plugin: 'kotlin-kapt' and implementation 'com.google.dagger:dagger:2.16' kapt 'com.google.dagger:dagger-compiler:2.16' Here is the code I am trying - class RanoBoilerplateApplication : Application(), HasActivityInjector{ @Inject lateinit var activityDispatchingAndroidInjector:

HasActivityInjector can not be resolved in android dagger 2

拜拜、爱过 提交于 2020-06-24 20:52:28
问题 I was trying to implement HasActivityInjector in my android application but it's showing me HasActivityInjector cann't be resolved. Below dependencies and plugin I have used in my project- apply plugin: 'kotlin-kapt' and implementation 'com.google.dagger:dagger:2.16' kapt 'com.google.dagger:dagger-compiler:2.16' Here is the code I am trying - class RanoBoilerplateApplication : Application(), HasActivityInjector{ @Inject lateinit var activityDispatchingAndroidInjector:

CustomScope may not reference bindings with different scopes

拥有回忆 提交于 2020-06-23 05:56:27
问题 I am new to dagger, I have defined my application component like this @Singleton @Component(modules = {ApplicationModule.class}) public interface ApplicationComponent { void inject(BaseActivity activity); Context context(); } This is my ApplicationModule @Module public class ApplicationModule { public TipoApplication application; public ApplicationModule(TipoApplication application) { this.application = application; } @Singleton @Provides public Context provideContext(){return application

CustomScope may not reference bindings with different scopes

帅比萌擦擦* 提交于 2020-06-23 05:56:05
问题 I am new to dagger, I have defined my application component like this @Singleton @Component(modules = {ApplicationModule.class}) public interface ApplicationComponent { void inject(BaseActivity activity); Context context(); } This is my ApplicationModule @Module public class ApplicationModule { public TipoApplication application; public ApplicationModule(TipoApplication application) { this.application = application; } @Singleton @Provides public Context provideContext(){return application

Inject only certain params in constructor

时光总嘲笑我的痴心妄想 提交于 2020-06-12 06:52:27
问题 I have the presenter class PhonePresenter @Inject constructor( private val preference: DataPreference, private val ioScheduler: Scheduler = Schedulers.io()) ioScheduler is a default parameter. I want to inject only preference: DataPreference . Now I have the exception [dagger.android.AndroidInjector.inject(T)] io.reactivex.Scheduler cannot be provided without an @Provides-annotated method. Is there any way to define parameters which I want to inject in a constructor? 回答1: Make inject

Use the same instance of view model in multiple fragments using dagger2

痴心易碎 提交于 2020-06-01 05:36:25
问题 I am using only dagger2 ( not dagger-android ) in my project. It's working fine to inject the ViewModel using multibinding. But there's one problem with that previously without dagger2 I was using the same instance of viewmodel used in activity in multiple fragments (using fragment-ktx method activityViewModels()), but now since dagger2 is injecting the view model it's always gives the new instance (checked with hashCode in each fragment) of the viewmodel for each fragment, that's just breaks

Android unit testing issues with dagger2 and kotlin

对着背影说爱祢 提交于 2020-05-28 06:39:09
问题 I am trying to create a dagger component interface in the test folder of android,but after Dagger is done with the generated class its show an error as "Cannot access TestComponent which is a supertype of com.example.animals.di.DaggerTestAppComponent.Check your module classpath for missing or conflicting dependency".Can you please help me to fix this issue. gradle dependecies: def lifeCycleExtensionVersion = '1.1.1' def supportVersion = '28.0.0' def retrofitVersion = '2.3.0' def glideVersion

Dagger 2 - two provides method that provide same interface

亡梦爱人 提交于 2020-05-22 13:35:12
问题 lets say I have: public interface Shape {} public class Rectangle implements Shape { } public class Circle implements Shape { } and I have a ApplicationModule which needs to provides instances for both Rec and Circle : @Module public class ApplicationModule { private Shape rec; private Shape circle; public ApplicationModule() { rec = new Rectangle(); circle= new Circle (); } @Provides public Shape provideRectangle() { return rec ; } @Provides public Shape provideCircle() { return circle; } }

Dagger 2 - two provides method that provide same interface

夙愿已清 提交于 2020-05-22 13:34:59
问题 lets say I have: public interface Shape {} public class Rectangle implements Shape { } public class Circle implements Shape { } and I have a ApplicationModule which needs to provides instances for both Rec and Circle : @Module public class ApplicationModule { private Shape rec; private Shape circle; public ApplicationModule() { rec = new Rectangle(); circle= new Circle (); } @Provides public Shape provideRectangle() { return rec ; } @Provides public Shape provideCircle() { return circle; } }

Why is dagger considered better for AWS lambda implementation than Guice?

不想你离开。 提交于 2020-05-16 03:41:36
问题 I know that dagger creates injection at compile time by generating code and hence its performance is better than Guice, which do it at runtime. But specifically for case of lambda, I see it mentioned at multiple places that Dagger is preferred. Is it because of the cold start problem? Because of the cold start problem in lambda, lambda keeps doing bootstrapping multiple times whenever it receives a request after long time. So, with dagger, bootstrapping would be much faster as compared to