dagger

Dagger 2 How to inject one class to multiple components using Sub components?

我的未来我决定 提交于 2019-12-23 22:11:39
问题 Can any please provide example code to achieve this scenario using sub components. In MyActivity i need to fulfill dependencies from multiple components. As you can see in below code MyActivity requies injection from compA via module classA and compB via module classB . @Component(modules = classA.class) interface compA { void inject(MyActivity target); } @Component(modules = classB.class) interface compB { void inject(MyActivity target); } I have been trying many different things for quite

Dagger: proper way to define injectable class that takes context in its constructor

混江龙づ霸主 提交于 2019-12-23 21:07:30
问题 I want to use dagger (dagger v1 by Square) to create a singleton class whose constructor requires context as an argument. I then want to inject this singleton class into my MainActivity. What are the proper steps to define this? I tried doing this: SingletonClass: @Module( injects = {MainActivity.class} ) @Singleton public class SingletonClass { ... @Inject SingletonClass(Context ctx) {} } to which I receive the error: no injectable members on android.content.Context I understand that

Dagger 2 - Injecting from multiple independently scoped components into a single object

痴心易碎 提交于 2019-12-23 17:25:02
问题 The issue that I'm facing is that I want to have two independent scopes that don't really fall into a parent-child hierarchy. In my case, I want two types of scopes: 1) "Feature" based scopes. e.g., when a user enters a feature, a scoped component is created. When the user leaves that feature, that scope is destroyed. 2) "Activity" based scopes (this is for an Android app, sorry about the terminology if you don't use Android). When an activity is created, a scoped component is created. When

Why do Dagger components have to declare their scope?

人走茶凉 提交于 2019-12-23 12:02:52
问题 Why do I have to annotate a Dagger component with the scopes it's going to use? Why is it not enough to annotate the class itself? 回答1: Because scopes by themselves don't mean anything. It's the components and their relationships that introduce meaning to scopes. Unscoped objects can be provided from any component if their dependencies are available. Since they are unscoped there will be a new object created every time that you call their provider. A scoped object will share the lifecycle of

java.lang.IllegalArgumentException: No injector factory bound for Class<MyActivity_>

人走茶凉 提交于 2019-12-23 08:54:03
问题 The error I have is following: Caused by: java.lang.IllegalArgumentException: No injector factory bound for Class. Injector factories were bound for supertypes of MyActivity_: [MyActivity]. Did you mean to bind an injector factory for the subtype? As I understand it happens because I am using an AndroidAnnotations library. AppComponent.class : @Singleton @Component(modules = { AndroidInjectionModule.class, AppModule.class, ActivityBindingModule.class }) public interface AppComponent extends

Dagger-android build errror cannot be provided without an @Provides-annotated method

淺唱寂寞╮ 提交于 2019-12-23 05:34:05
问题 I am learning dagger dependency injection(I know i am late to the party, its better to start now). But I am facing below error. Please any help or suggestion could be greatly appreciated. ERROR Log error: [Dagger/MissingBinding] [dagger.android.AndroidInjector.inject(T)] @com.mypackage.di.key.ItemDetail java.lang.Integer cannot be provided without an @Provides-annotated method. public interface ApplicationComponent extends AndroidInjector<RetailShopApplication> { ^ @com.mypackage.di.key

Overriding debug module in tests

无人久伴 提交于 2019-12-22 09:57:02
问题 I have a Gradle app with a project structure similar to Jake Wharton's u2020: /src /androidTest /debug /main /release In my application class I build the Dagger graph and inject it: MyApplication extends Application { ... public void buildObjectGraphAndInject() { Object[] modules = Modules.list(this); mApplicationGraph = ObjectGraph.create(modules); mApplicationGraph.inject(this); } ... } Inside the debug sourceset, I define Modules.list() as: public final class Modules { public static Object

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

Is it possible to integrate Dagger and AspectJ in an Android Studio project?

女生的网名这么多〃 提交于 2019-12-22 05:08:16
问题 I'm working in an Android project where I'm using Dagger for dependency injection. I don't know so much about Gradle, but as far as I understand, the Dagger annotations are processed by its compiler once the project is built. There's no problem in configuring it as the user guide says. Well, now I want to integrate AspectJ too, so I'm looking at one of the plugins for Android. However, it seems this plugin does a build post processing job to read the aspects too, which remains in conflict