dagger-2

kotlin + Dagger2 : cannot be provided without an @Provides-annotated method

别等时光非礼了梦想. 提交于 2019-12-21 06:59:57
问题 I don't understand why am I getting this error: Error:(12, 2) error: [dagger.android.AndroidInjector.inject(T)] java.util.Map<java.lang.Class<? extends android.arch.lifecycle.ViewModel>,? extends javax.inject.Provider<android.arch.lifecycle.ViewModel>> cannot be provided without an @Provides-annotated method. public abstract interface ApplicationComponent { ^ java.util.Map<java.lang.Class<? extends android.arch.lifecycle.ViewModel>,? extends javax.inject.Provider<android.arch.lifecycle

Can I use Dagger 2's field injection in Kotlin?

谁说我不能喝 提交于 2019-12-21 06:58:20
问题 I posted a question (Dagger 2 does not generate the component class (Android, Kotlin)), and after some experiments, it seems that the problem might be due to that Kotlin hides the field. class CoffeeShop { @Inject var theCoffee: Coffee? = null } The error message is, :app:kaptDebugKotline: ...\CoffeeShop.java:7: error: Dagger does not support injection into private fields e: private ....Coffee theCoffee; theCoffee was not private in my source code. But I think Kotlin may be translating class

Injecting application context in library module with Dagger 2

喜夏-厌秋 提交于 2019-12-21 04:46:08
问题 I'm building an app with some features: a ContentProvider a SyncAdapter, a Job service and related persistence logic. On top on these there are the Activities with the UI. I'm trying to put all said features in a separate library module, because in theory their logic is stand-alone and would be reusable by any application. Now comes Dagger2. The first node (main Component) of my library's dependency graph does need to provide Context, and this Context has to be injected from the Application,

What is the use case for @Binds vs @Provides annotation in Dagger2

浪子不回头ぞ 提交于 2019-12-21 03:59:18
问题 I am not certain on the purpose for Dagger2's @Bind annotation. From what i have read online im still not clear but here is an example: @Module public abstract class HomeModule { @Binds public abstract HomePresenter bindHomePresenter(HomePresenterImp homePresenterImp); } and the class definitions look like this: public interface HomePresenter { Observable<List<User>> loadUsers(); } public class HomePresenterImp implements HomePresenter { public HomePresenterImp(){ } @Override public

dagger android support to androidx.fragment

时光毁灭记忆、已成空白 提交于 2019-12-20 17:33:24
问题 How to inject a fragment from the package androidx.fragment.app.Fragment ? I'm using the dagger-android framework to inject my dependencies in my code. As the documentation says I do this to inject my fragment @Override public void onAttach(Activity activity) { AndroidInjection.inject(this); super.onAttach(activity); // ... } the problem is that AndroidSupportInjection class accept only fragments of the package android.support.v4.app.Fragment or if I use AndroidInjection class only accept

Android Kotlin : Error Unresolved reference: DaggerAppComponent

空扰寡人 提交于 2019-12-20 17:28:33
问题 I have installed Kotlin plugin today into an existing project with Dagger 2. Before Kotlin was installed I had no issues with Dagger. However, now the compiler complains : Error:(5, 32) Unresolved reference: DaggerAppComponent Error:Execution failed for task ':app:compileDebugKotlinAfterJava'. > Compilation error. See log for more details Error:(12, 21) Unresolved reference: DaggerAppComponent Project gradle: ext.kotlin_version = '1.1.1' repositories { jcenter() } dependencies { classpath

Dagger 2: When to use constructor injections and when to use field injections?

不羁的心 提交于 2019-12-20 11:22:41
问题 I was kind of lazy and used to use almost entirely field injections. I was just providing empty constructor, put my @Inject fields I everything was looking nice and simple. However field injection have its trade-offs so I've devised some simple rules that help me to decide when to used field and when to use constructor injections. I will appreciate any feedback if there is mistake in my logic or if you have additional considerations to add. First some clarification in order to be on the same

Dagger and Kotlin. Dagger doesn't generate component classes

自闭症网瘾萝莉.ら 提交于 2019-12-20 11:01:18
问题 I'm new with kotlin and Dagger. I have a little problem that I do not how to solve and I don't find a solution. So this is what I have: @Module class AppModule (app: Application) { private var application: Application; init { this.application = app; } @Provides fun provideApplication(): Application? { return application; } @Provides fun provideResources(): Resources? { return application.resources; } } @Singleton @Component(modules = arrayOf(AppModule::class)) interface AppComponent:

Dagger 2 - what is the purpose of a @Singleton annotation class

試著忘記壹切 提交于 2019-12-20 10:59:34
问题 From the dagger 2 Documentation I noticed that you can have a @Singleton annotated class. What is the purpose of marking a class as @Singleton as I have tried to do this in my code but a singleton object is NOT produced. I'm not clear on what use marking my class with this annotation serves. From the documentation please focus on the following statement: The @Singleton annotation on an injectable class also serves as documentation. It reminds potential maintainers that this class may be

android getting NULL error on inject DI into class

旧巷老猫 提交于 2019-12-20 07:38:47
问题 I can make DI from some class to use in application such as Retrofit , Picasso . they can work fine when i use them on Activity but when i try to use some DI on other class i get NULL, for exmple this code work fine public class ActivityRegister extends BaseActivities { @Inject GithubService githubService; @Inject JobManager jobManager; @Override public void onCreate(@Nullable Bundle savedInstanceState) { ... repositoryCall = githubService.getAllRepositories(); ... } private void