dagger-2

Dagger 2 injecting two retrofit objects

倾然丶 夕夏残阳落幕 提交于 2019-12-22 10:33:33
问题 I'm using Dagger 2 with retrofit2 library while using MVP. Everything went well till I tried to integrate another service (basically I tried to initialize another retrofit object to another service). I followed this answer but without any success. Every time I'm getting an errors that each of my fragments and application classes don't seem to recognize the component classes. error: cannot find symbol class DaggerApplicationComponent error: cannot find symbol class DaggerEpisodeComponent Code

Dagger2: Injecting implementation classes provided by modules with component itself

爷,独闯天下 提交于 2019-12-22 09:51:51
问题 Considering modules are all shared among one-another through the Dagger1 specification of complete=false, library=true , you can receive the elements provided by the @Provides methods through a constructor parameter, like so. public class GetUserForUsernameTaskImpl implements GetUserForUsernameTask { public static final String TAG = GetUserForUsernameTaskImpl.class.getSimpleName(); private Realm realm; private UserRepository userRepository; public GetUserForUsernameTaskImpl(Realm realm,

Android Dagger 2 Dependency not being injected

好久不见. 提交于 2019-12-22 08:53:44
问题 i'm trying to use Dagger 2 into my apps but i'm having some problems regarding the entities repository and i haven't figured it out what i'm missing. Here is my Application Component: @Singleton @Component( modules = { AndroidModule.class, RepositoryModule.class } ) public interface ApplicationComponent { void inject(AndroidApplication app); IDependenceyRepository dependencyRepository(); } My modules: @Module public class RepositoryModule { @Provides @Singleton IDependenceyRepository

Kotlin + Dagger inject issue depending on device's Android Version / SDK (?)

走远了吗. 提交于 2019-12-22 08:14:22
问题 Last week, while implementing Dagger in my current Kotlin MVP project, I was testing it on oldy phone with KitKat 4.4.2 (yep, it still supports all major material features and stuff :)) due to primary phone's maintenance. So that week I was having typical issues rather than something unusual and fixed them more or less quickly by investigating provided errors. At long last, code compiled, current project version was built without issues and ran without major bugs on KitKat with UI interacting

How can I replace Activity scoped dependencies with mocks using Dagger2

删除回忆录丶 提交于 2019-12-21 17:49:14
问题 I have a scoped dependency in my Activity and I want to test that activity with some mocks. I have read about different approach that suggest to replace Application component with a test component during the test, but what I want is to replace the Activity component. For example, I want to test the Activity against mock presenter in my MVP setup. I believe that replacing component by calling setComponent() on Activity will not work, because Activity dependencies already injected via field

Dagger 2 : How to bind Fragment Map in parent component from subcomponent for FragmentFactory

允我心安 提交于 2019-12-21 12:29:14
问题 I have this Dagger 2 configuration: AppComponent.kt @Singleton @Component( modules = [ AndroidSupportInjectionModule::class, AppModule::class, ActivityBindingModule::class, ] ) interface AppComponent : AndroidInjector<AppApplication> { @Component.Builder abstract class Builder : AndroidInjector.Builder<AppApplication>() } ActivityBindingModule.kt @Module abstract class ActivityBindingModule { @ActivityScoped @ContributesAndroidInjector( modules = [ MainActivityModule::class, FragmentModule:

Dagger 2 : How to bind Fragment Map in parent component from subcomponent for FragmentFactory

可紊 提交于 2019-12-21 12:26:15
问题 I have this Dagger 2 configuration: AppComponent.kt @Singleton @Component( modules = [ AndroidSupportInjectionModule::class, AppModule::class, ActivityBindingModule::class, ] ) interface AppComponent : AndroidInjector<AppApplication> { @Component.Builder abstract class Builder : AndroidInjector.Builder<AppApplication>() } ActivityBindingModule.kt @Module abstract class ActivityBindingModule { @ActivityScoped @ContributesAndroidInjector( modules = [ MainActivityModule::class, FragmentModule:

Beside testing, why do we need Dagger 2?

久未见 提交于 2019-12-21 07:45:39
问题 At this point, my understanding of Dependency Injection (DI) is only from this article. I'm interested to try, but I just need to clarify some things: Many refer DI as a tool to reduce boilerplate code. But according to that tutorial, the setup of Dagger 2 tends to create even more classes for configuration (module and component). I have not tried it, but by the looks of it, it isn't reducing the code, it is just splitting them so the main class can look tidier. Am I wrong on this one?

Beside testing, why do we need Dagger 2?

三世轮回 提交于 2019-12-21 07:44:48
问题 At this point, my understanding of Dependency Injection (DI) is only from this article. I'm interested to try, but I just need to clarify some things: Many refer DI as a tool to reduce boilerplate code. But according to that tutorial, the setup of Dagger 2 tends to create even more classes for configuration (module and component). I have not tried it, but by the looks of it, it isn't reducing the code, it is just splitting them so the main class can look tidier. Am I wrong on this one?

Purpose of proxyProvide in Dagger 2 generated code

柔情痞子 提交于 2019-12-21 07:39:24
问题 I have this Dagger module. I want to understand the generated code so I can verify that my Dagger configuration is optimal. @Module public class TypefaceModule { @Provides @Singleton @Named("Roboto Light") static Typeface provideRobotoLight(AssetManager assets) { return Typeface.createFromAsset(assets, "fonts/Roboto-Light.ttf"); } } Here's the generated code (Dagger 2.14.1): public final class TypefaceModule_ProvideRobotoLightFactory implements Factory<Typeface> { private final Provider