dagger-2

Why use/develop Guice, when You have Spring and Dagger? [closed]

青春壹個敷衍的年華 提交于 2020-03-17 04:08:45
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . To my knowledge, Dagger does generate code, while Guice and Spring rely on runtime processing, thus Dagger works faster, but requires more work on programmer side. Because of performance edge it's good for mobile (Android) development. However, when we are left with Guice and

How to inject primitive variables in Kotlin?

吃可爱长大的小学妹 提交于 2020-03-13 05:57:47
问题 I am using Dagger2 for DI in my Android app, and using this code for injecting classes into my Activity is fine: @field:[Inject ApplicationContext] lateinit var context: Context but, lateinit modifier is not allowed on primitive type properties in Kotlin (for instance Boolean ), how can I do something like this? @field:[Inject Named("isDemo")] lateinit var isDemo: Boolean when I remove lateinit from this code I get this error Dagger does not support injection into private fields 回答1: First,

How to inject primitive variables in Kotlin?

旧城冷巷雨未停 提交于 2020-03-13 05:56:58
问题 I am using Dagger2 for DI in my Android app, and using this code for injecting classes into my Activity is fine: @field:[Inject ApplicationContext] lateinit var context: Context but, lateinit modifier is not allowed on primitive type properties in Kotlin (for instance Boolean ), how can I do something like this? @field:[Inject Named("isDemo")] lateinit var isDemo: Boolean when I remove lateinit from this code I get this error Dagger does not support injection into private fields 回答1: First,

How to inject primitive variables in Kotlin?

*爱你&永不变心* 提交于 2020-03-13 05:56:03
问题 I am using Dagger2 for DI in my Android app, and using this code for injecting classes into my Activity is fine: @field:[Inject ApplicationContext] lateinit var context: Context but, lateinit modifier is not allowed on primitive type properties in Kotlin (for instance Boolean ), how can I do something like this? @field:[Inject Named("isDemo")] lateinit var isDemo: Boolean when I remove lateinit from this code I get this error Dagger does not support injection into private fields 回答1: First,

Do we really need viewModelFactories and viewmodelProviders when using Dagger?

橙三吉。 提交于 2020-03-05 03:11:08
问题 So I was working on some sample MVVM project using Dagger. I have a viewmodel factory that goes like this: class DaggerViewModelFactory @Inject constructor(private val viewModelsMap: Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>) : ViewModelProvider.Factory { override fun <T : ViewModel> create(modelClass: Class<T>): T { val creator = viewModelsMap[modelClass] ?: viewModelsMap.asIterable().firstOrNull { modelClass.isAssignableFrom(it.key) }?.value ?: throw

Android Kotlin: integration tests using Dagger 2 and Mockito getting error, “zero interactions with this mock”

試著忘記壹切 提交于 2020-03-04 19:36:08
问题 I am developing an Android application using Kotlin. I am writing integration tests for my application. Now I am having a problem mocking an injected dependency class that is injected using the Dagger 2 test if a method of the mocked object is called. Following is my code. I have the TestAppComponent class with the following code @Singleton @Component(modules = [ TestAppModule::class ]) interface TestAppComponent { fun inject(app: ApplicationController) fun inject(app:

Dagger2 Circular Dependency Error

五迷三道 提交于 2020-03-04 18:31:04
问题 I am using dagger2 2.16 version for dependency injection inside mine android project. I examine a lot of examples, and although I do not have a similar approach I get the error of "circular dependency". Mine source code; AppComponent.kt @Singleton @Component( modules = [ AndroidSupportInjectionModule::class, AppModule::class, ActivityBuilderModule::class] ) interface AppComponent { @Component.Builder interface Builder { @BindsInstance fun application(application: Application): Builder fun

Inject ViewModel using Dagger 2 + Kotlin + ViewModel

假如想象 提交于 2020-02-27 04:36:45
问题 class SlideshowViewModel : ViewModel() { @Inject lateinit var mediaItemRepository : MediaItemRepository fun init() { What goes here? } So I'm trying to learn Dagger2 so I can make my apps more testable. Problem is, I've already integrated Kotlin and am working on the Android Architectural components. I understand that constructor injection is preferable but this isn't possible with ViewModel . Instead, I can use lateinit in order to inject but I'm at a loss to figure out how to inject. Do I

Supporting a Dagger 2 dependency in a Dagger 1 project

折月煮酒 提交于 2020-02-25 02:13:10
问题 This is a follow-up to my question about Play Services Cast Framework, where the solution seems to be updating from v17.0.0 to v18.0.0. The new version unfortunately has a dependency on Dagger 2, whilst the (large & complex) project is Dagger 1. We are currently using: api "com.google.android.gms:play-services-cast:17.0.0" api "com.google.android.gms:play-services-cast-framework:17.0.0" Updating these to 18.0.0 results in: > 1 exception was raised by workers: java.lang.RuntimeException:

Supporting a Dagger 2 dependency in a Dagger 1 project

我的未来我决定 提交于 2020-02-25 02:10:11
问题 This is a follow-up to my question about Play Services Cast Framework, where the solution seems to be updating from v17.0.0 to v18.0.0. The new version unfortunately has a dependency on Dagger 2, whilst the (large & complex) project is Dagger 1. We are currently using: api "com.google.android.gms:play-services-cast:17.0.0" api "com.google.android.gms:play-services-cast-framework:17.0.0" Updating these to 18.0.0 results in: > 1 exception was raised by workers: java.lang.RuntimeException: