dagger-2

How do I make Dagger 1 and Dagger 2 coexist together in one Android project?

你离开我真会死。 提交于 2020-08-09 18:51:28
问题 We have a huge codebase to migrate from dagger 1 to dagger 2 but we would like to do it step by step. For that we were thinking to have both versions as our project dependency and do the migration module by module. But we were unable to make it work. This is the article we referred https://fernandocejas.com/2016/08/03/android-dagger-1-and-2-living-together/ but without any luck or is there any other way? Thanks. 回答1: There's no other way. When trying to use both Dagger versions together, you

How do I make Dagger 1 and Dagger 2 coexist together in one Android project?

蹲街弑〆低调 提交于 2020-08-09 18:50:59
问题 We have a huge codebase to migrate from dagger 1 to dagger 2 but we would like to do it step by step. For that we were thinking to have both versions as our project dependency and do the migration module by module. But we were unable to make it work. This is the article we referred https://fernandocejas.com/2016/08/03/android-dagger-1-and-2-living-together/ but without any luck or is there any other way? Thanks. 回答1: There's no other way. When trying to use both Dagger versions together, you

How do I make Dagger 1 and Dagger 2 coexist together in one Android project?

陌路散爱 提交于 2020-08-09 18:50:30
问题 We have a huge codebase to migrate from dagger 1 to dagger 2 but we would like to do it step by step. For that we were thinking to have both versions as our project dependency and do the migration module by module. But we were unable to make it work. This is the article we referred https://fernandocejas.com/2016/08/03/android-dagger-1-and-2-living-together/ but without any luck or is there any other way? Thanks. 回答1: There's no other way. When trying to use both Dagger versions together, you

How to prevent Hilt from picking dependency from a library?

a 夏天 提交于 2020-08-09 08:17:06
问题 Okay, let's make this simple. I have created a simple library called my-network-library with two classes in it. First one is a Hilt module called BaseNetworkModule @Module @InstallIn(ApplicationComponent::class) object BaseNetworkModule { // Client @Singleton @Provides fun provideOkHttpClient(): OkHttpClient { return OkHttpClient.Builder() // my default okhttp setup goes here .build() } } and the second one is a simple class. class MyAwesomeClass { fun doMagic() { // magic code goes here } }

Dagger 2 get own Room instance

*爱你&永不变心* 提交于 2020-08-05 07:04:45
问题 I want to add a callback to the room database to populate initial data. @Provides @Singleton fun provideRoom(context: Context): MyRoomDatabase { return Room.databaseBuilder(context, MyRoomDatabase::class.java, "my_database") .fallbackToDestructiveMigration() .addCallback(object : RoomDatabase.Callback() { @Override override fun onCreate(db: SupportSQLiteDatabase) { super.onCreate(db) } }) .build() } For that i need the database instance in the callback to access DAO for inserting data. How

Dagger2 - How to use @Named with @BindsInstance

六眼飞鱼酱① 提交于 2020-07-21 07:30:28
问题 How is @Named used with @BindsInstance? I have the this component interface AppComponent : AndroidInjector<MyApplication>{ @Component.Builder abstract class Builder : AndroidInjector.Builder<MyApplication>() { @BindsInstance abstract fun preferenceName( @Named("PreferenceName") name : String ) : Builder } } and trying to inject in MyApplication @Inject @Named("PreferenceName") lateinit var prefName : String But it fails with MissingBinding for String. I could resolve this with a module

Error [Dagger/MissingBinding] androidx.lifecycle.ViewModelProvider.Factory cannot be provided without an @Provides-annotated method

淺唱寂寞╮ 提交于 2020-07-21 07:11:10
问题 I am facing an issue while implementing MultiBinding using dagger 2.2. I am using dagger with MVVM architecture. I have injected the ViewModelProvideFactory constructor and binds the dependency from module. I have followed the tutorial of Mitch from youtube https://www.youtube.com/watch?v=DToD1W9WdsE&list=PLgCYzUzKIBE8AOAspC3DHoBNZIBHbIOsC&index=13 I have searched on these links for the solutions but still facing the same issue. Dagger2: ViewModel cannot be provided without an @Provides

Dagger2 is not generating classes in android

一笑奈何 提交于 2020-07-09 13:42:08
问题 I am using Dagger2 in my android application, I have two component in my application. First is global for entire application and second is specific to activity instance. NetComponent.java @Singleton @Component(modules = {AppModule.class, NetModule.class}) public interface NetComponent { void inject(AuthenticationActivity authenticationActivity); void inject(PaymentActivity paymentActivity); } ValidationComponent.java @Singleton @Component(modules = {ValidatorModule.class}) public interface

How i can add view model in module?

时光怂恿深爱的人放手 提交于 2020-06-29 05:26:15
问题 In Dagger, how can I add a model to Module? For example I added the presenter in the following way: @Module class AboutModule(val appContext: Context) { @FragmentScope @Provides fun providePresenter(): AboutListContract.Presenter { return AboutListPresenter(appContext = appContext) } } Now i want want to add my View model, also with appContext. class AboutViewModel(val appContext: Context): ViewModel() { UPDATE: Can i add my view model smth like this? @Module class AboutModule(val appContext:

Dagger2 Error at inject in a class who injects

橙三吉。 提交于 2020-06-29 03:41:55
问题 I'm trying to inject in my presenter an interactor but gives me an error, at seems I can't inject in a class who injects to another: error: [Dagger/DuplicateBindings] com.example.calculadora.Data.Interactor.Operacion is bound multiple times: @Provides com.example.calculadora.Data.Interactor.Operacion com.example.calculadora.Inject.InteractorModule.provideDiv() @Provides com.example.calculadora.Data.Interactor.Operacion com.example.calculadora.Inject.InteractorModule.provideMult() @Provides