dagger-2

Dagger 2 activity injection not working

[亡魂溺海] 提交于 2019-12-07 16:30:58
问题 I'm trying the new dagger 2, it's my first time implementing it but I can't make it work. I think I got the concept and I understand the example here I try to copy the same structure just a bit modified for my example. Here is the AppComponent that extends the Graph where I defined the classes I want. @ApplicationScope @Component(modules = {AppModule.class, DataModule.class}) public interface EFAppComponent extends EFGraph { /** * An initializer that creates the graph from an application. */

Dagger 2 inject method

最后都变了- 提交于 2019-12-07 14:26:37
问题 I'm playing around with Dagger 2. I have the following Module : @Module public class GameSetupModule { @Provides @Singleton GameSetup provideGameSetup() { return new GameSetup(); } } and the according Component : @Singleton @Component(modules = {GameSetupModule.class}) public interface GameSetupComponent { GameSetup provideGameSetup(); void inject(SetupActivity activity); // void inject(Fragment fragment); void inject(SetupCompletedFragment fragment); void inject(SelectQuarterLengthFragment

What is the prefered way to save/restore screen state with Flow + Mortar + Dagger2?

爱⌒轻易说出口 提交于 2019-12-07 14:26:32
问题 I'm trying to convert an Acticity + Fragments app to Flow + Mortar + Dagger2 I would like to save & restore screen state when jumping from screen to screen (at least backwards). What is the prefered/recommanded way to do that ? I have spent quite a lot of time looking at flow and mortar readmes and samples but couldn't figure it out (the documentation and samples are minimal and only deal with simple/static/unique data). Say, for example, you have a browser-like app that moves from Page to

Dagger 2 Component with differently scoped modules

限于喜欢 提交于 2019-12-07 12:32:14
问题 Context I have two Dagger 2 modules: NetworkModule , with @Singleton scope, that provides an HTTP client; ApiModule , with a custom @UserScope scope, that uses the HTTP client to create a consumer for Github's API. Then, I create a Dagger 2 component, to provide the Retrofit client. NetworkModule.kt @Module class NetworkModule { @Provides @Singleton fun provideHttpClient(): OkHttpClient = OkHttpClient.Builder().build() } ApiModule.kt @Module(includes = [NetworkModule::class]) class ApiModule

Dagger - Getting Same Instance On Different Component

这一生的挚爱 提交于 2019-12-07 12:26:54
问题 I'm having a similar problem like the one in this question. While the accepted answer does help, but I'm missing final piece to solve the problem. I have 2 android library modules: common and exp which depends on common . Everything under common : @Module public class CommonModule { @Singleton @Provides public Repository providesRepository() { return new Repository(); } } @Singleton @Component(modules={CommonModule.class}) public interface CommonComponent { void inject(CommonClass commonClass

What is the difference between Dagger and Dagger 2.0?

跟風遠走 提交于 2019-12-07 11:10:33
问题 What is the difference between Dagger and Dagger 2.0, and why did Google decide to fork the existing project? 回答1: Some quotes from the Dagger 2 presentation Issues of Dagger 1: Ugly generated code Runtime graph composition Inefficient graph creation Partial traceability Map-like API Dagger 2 solutions: Compile-time validation of the entire graph Easy debugging; entirely concrete call stack for provision and creation Fully traceable POJO API Performance Dagger 2 issues: Less flexible No

Dagger 2: How to inject Map<Class<? extends Foo>, Provider<? extends Foo>>

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 10:49:59
问题 In Dagger 2, is it possible to inject a Map<Class<? extends Foo>, Provider<? extends Foo>> ? Suppose, I have a couple of classes that extends Foo class Bar extends Foo { @Inject Bar() {} } class Baz extends Foo { @Inject Baz() {} } and now I want to create a FooFactory by declaring class FooFactory { @Inject FooFactory(Map<Class<? extends Foo>, Provider<? extends Foo>> providers) {} } Can I do this in Dagger 2 with minimal configuration? I've read about Multibinding but I couldn't get it to

Dagger2 androidTest error duplicate entry: javax/annotation/Generated.class

拟墨画扇 提交于 2019-12-07 07:01:36
问题 I'm using Dagger2 for DI. My project has 2 modules, a :common module which is a library and an :app module which is the actual application. In the library module I have AndroidApp which extends MultiDexApplication and is inherited in :app module. I have followed Google's dagger2 example to add DI with Dagger2. Each time I run the app I get the following message as an error: Android/common/src/main/java/com/common/AndroidApp.java:10: The import com.common.di.DaggerAndroidAppComponent cannot be

Dagger 2 Dependency Injection in Android TestCase

 ̄綄美尐妖づ 提交于 2019-12-07 06:00:59
问题 I have built up an example application (Yes, it is really just an example and doesn’t make much sense but is good for understanding Android clean architecture and dependency injection in Dagger 2). My code is available on github.(Outdated. See this post) The example app just let’s you type in a name in an EditText and if you press the Button you see a message "Hello YourName" I have three different Components: ApplicationComponent , ActivityComponent and FragmentComponent . FragmentComponent

Dagger 2 injection not working

徘徊边缘 提交于 2019-12-07 05:11:09
问题 The module that proides singletons of Gson, Retrofit and OkHttpClient @Module public class MyModule { @Provides @Singleton Gson provideGson() { GsonBuilder gsonBuilder = new GsonBuilder(); return gsonBuilder.create(); } @Provides @Singleton OkHttpClient provideOkHttpClient() { OkHttpClient client = new OkHttpClient(); return client; } @Provides @Singleton Retrofit provideRetrofit(Gson gson, OkHttpClient okHttpClient) { Retrofit retrofit = new Retrofit.Builder() .addConverterFactory