dagger-2

Dagger2 Inject class with parameter (using Room)

僤鯓⒐⒋嵵緔 提交于 2020-01-25 08:17:12
问题 I have a problem with injecting classes with Dagger2 . I am using RoomDatabase for database access. My room setup: Dao's interface noteDao() interface noteTypeDao() interface userDao() NoteRepository @Singleton class NoteRepository @Inject constructor( private val noteDao: NoteDao, private val noteTypeDao: NoteTypeDao, private val userDao: UserDao ) { } AppDatabase @Database(entities = [Note::class, User::class, NoteType::class], version = 1) abstract class AppDatabase : RoomDatabase() {

Not able to inject a multi-binding with kotlin and dagger

只谈情不闲聊 提交于 2020-01-24 17:28:25
问题 I have the following definitions: @Module class WeaverDataModule { // Provide the three pumps from providers // All of them still explicitly mark 'Pump' as their return type @Provides @IntoSet fun providesPump(thermosiphon: Thermosiphon) : Pump = thermosiphon @Provides @IntoSet fun providesAnotherPump(suctionBased: SuctionBased) : Pump = suctionBased @Provides @IntoSet fun providesGenericPump(genericPump: GenericPump) : Pump = genericPump } @Component(modules = [WeaverDataModule::class])

<android.arch.lifecycle.ViewModel>> cannot be provided without an @Provides-annotated method

杀马特。学长 韩版系。学妹 提交于 2020-01-24 09:20:13
问题 I am trying to create a viewmodel module like in this example but I am having this error error: java.util.Map,javax.inject.Provider> cannot be provided without an @Provides-annotated method. I followed all the example, here are my codes ViewModelFactory class @Singleton public class ViewModelFactory implements ViewModelProvider.Factory { private final Map<Class<? extends ViewModel>, Provider<ViewModel>> mCreators; @Inject ViewModelFactory(Map<Class<? extends ViewModel>, Provider<ViewModel>>

Dagger singleton vs kotlin object

℡╲_俬逩灬. 提交于 2020-01-24 02:12:04
问题 To define a singleton, should I use kotlin object declaration or to make an ordinary kotlin class and inject it using dagger? In my opinion the first option is definitely easier but there may be a reason to use dagger in this situation that I'm not aware of. Option 1 (notice object keyword): object SomeUtil { // object state (properties) fun someFunction(number: Long) { // ... } } Option 2 (notice class keyword): class SomeUtil { // object state (properties) fun someFunction(number: Long) { /

Presenter injection with Dagger 2

杀马特。学长 韩版系。学妹 提交于 2020-01-22 12:13:07
问题 I just started using Dagger 2 and I found online thousands guides each one with a different implementation and I'm a bit confused now. So basically this is what I wrote at the moment: AppModule.java: @Module public class AppModule { Application mApplication; public AppModule(Application application) { mApplication = application; } @Provides @Singleton Application providesApplication() { return mApplication; } } DataModule.java: @Module public class DataModule { private static final String

Presenter injection with Dagger 2

那年仲夏 提交于 2020-01-22 12:12:18
问题 I just started using Dagger 2 and I found online thousands guides each one with a different implementation and I'm a bit confused now. So basically this is what I wrote at the moment: AppModule.java: @Module public class AppModule { Application mApplication; public AppModule(Application application) { mApplication = application; } @Provides @Singleton Application providesApplication() { return mApplication; } } DataModule.java: @Module public class DataModule { private static final String

Presenter injection with Dagger 2

扶醉桌前 提交于 2020-01-22 12:12:04
问题 I just started using Dagger 2 and I found online thousands guides each one with a different implementation and I'm a bit confused now. So basically this is what I wrote at the moment: AppModule.java: @Module public class AppModule { Application mApplication; public AppModule(Application application) { mApplication = application; } @Provides @Singleton Application providesApplication() { return mApplication; } } DataModule.java: @Module public class DataModule { private static final String

Is this a correct way to use Dagger 2 for Android app in unit test to override dependencies with mocks/fakes?

自作多情 提交于 2020-01-22 05:55:27
问题 For 'regular' Java project overriding the dependencies in the unit tests with mock/fake ones is easy. You have to simply build your Dagger component and give it to the 'main' class that drives you application. For Android things are not that simple and I've searched for a long time for decent example but I was unable to find so I had to created my own implementation and I will really appreciate feedback is this a correct way to use Dagger 2 or there is a simpler/more elegant way to override

Can I use some kind of assisted Inject with Dagger?

99封情书 提交于 2020-01-19 04:11:05
问题 With Google Guice or Gin I can specify parameter with are not controlled by the dependency injection framework: class SomeEditor { @Inject public SomeEditor(SomeClassA a, @Assisted("stage") SomeClassB b) { } } The assisted parameter stage is specified at the time an instance of SomeEditor is created. The instance of SomeClassA is taken from the object graph and the instance of SomeClassB is taken from the caller at runtime. Is there a similar way of doing this in Dagger? 回答1: Because

Can I use some kind of assisted Inject with Dagger?

喜你入骨 提交于 2020-01-19 04:10:37
问题 With Google Guice or Gin I can specify parameter with are not controlled by the dependency injection framework: class SomeEditor { @Inject public SomeEditor(SomeClassA a, @Assisted("stage") SomeClassB b) { } } The assisted parameter stage is specified at the time an instance of SomeEditor is created. The instance of SomeClassA is taken from the object graph and the instance of SomeClassB is taken from the caller at runtime. Is there a similar way of doing this in Dagger? 回答1: Because