dagger-2

Dagger 2 with Kotlin, returning type with generic in ApplicationComponent

心不动则不痛 提交于 2019-12-06 02:51:08
问题 I want to return type with generic to be exposed by sub-graphs, the problem is in auto-generated java-classes, I tried to do something, but the one way to solve it is to remove generic type from AppComponent and return simple object. Is there more "right" approach? Here is the AppComponent @Singleton @Component(modules = arrayOf(ApplicationModule::class)) interface ApplicationComponent { fun inject(activity: BaseActivity<MvpView, MvpPresenter<MvpView>>) //... fun dataBase(): Database<Realm> }

NoClassDefFoundError When Using Dagger 2 After Switching to Android Studio 2.0

房东的猫 提交于 2019-12-05 23:43:50
问题 Before upgrading to Android Studio 2.0 I could use Dagger 2 no problem. Now I am getting a NoClassDefFoundError This has shut me down for more than a day and I'm reaching out for some help. It seems as though Gradle cannot my AppModule class even though it is pretty clear that it is in my project. I have even included set multiDexEnabled true even though my project is only a few files. Everything I can find online says that you can click your libraries to be imported. Android Studio has no

Dagger 2 activity injection not working

走远了吗. 提交于 2019-12-05 22:56:05
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. */ public final static class Initializer { private Initializer() { } // No instances. public static

Dagger2: no injector factory bound for fragment

99封情书 提交于 2019-12-05 22:39:26
问题 I'm trying to convert a project that I'm building to use the dagger-android API for the DI framework, but I'm running into a dead end with an IllegalArgumentException when trying to inject a fragment using @ContributesAnroidInjector. The relevant modules and components are included below: ApplicationComponent.java @Singleton @Component(modules = {AndroidSupportInjectionModule.class, ApplicationModule.class, ActivityBindingModule.class, DataManagerModule.class}) public interface

Multiple @Binds with same return class but different key

痴心易碎 提交于 2019-12-05 21:18:37
All the following are used with dagger 2.10 and dagger.android package. Say I have a class I'd like to inject in multiple activities. public class DemoSharedClass { Activity activity; @Inject public DemoSharedClass(Activity activity) { this.activity = activity; } } Then, using the latest Dagger APIs, my classes are defined as public class DemoActivity extends DaggerActivity { @Inject DemoSharedClass demoSharedClass; // ... } public class Demo2Activity extends DaggerActivity { @Inject DemoSharedClass demoSharedClass; // ... } Each activity has its module and subcomponent define as (exactement

Error: cannot find symbol variable DaggerAppComponent

孤者浪人 提交于 2019-12-05 20:08:05
问题 While trying to integrate latest Dagger 2 version, I am facing problem of Dagger auto generation. Dagger is not auto generating DaggerAppComponent in spite of several Rebuilds and Make Module App process. Application class: public class BaseApplication extends Application { private AppComponent appComponent; @Override public void onCreate() { super.onCreate(); initAppComponent(); } private void initAppComponent() { DaggerAppComponent.builder() .appModule(new AppModule(this)) .build(); }

Dagger 2 Component with differently scoped modules

老子叫甜甜 提交于 2019-12-05 18:49:58
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(private val user: String) { @Provides @UserScope fun provideApi(httpClient: OkHttpClient): GithubApi =

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

情到浓时终转凉″ 提交于 2019-12-05 18:30:25
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 Page Where each Page use the same same PageView class, the same PagePresenter Class but have different

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

只谈情不闲聊 提交于 2019-12-05 18:19:20
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. But when I took main phone with Nougat 7.1.2 from repair center and launched app on it I stuck with

What is the difference between Dagger and Dagger 2.0?

北城以北 提交于 2019-12-05 18:03:54
What is the difference between Dagger and Dagger 2.0, and why did Google decide to fork the existing project? 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 dynamism No automated migration path from Guice 来源: https://stackoverflow.com/questions/27888580/what-is-the