dagger-2

Multi-layer / libraries architecture with dagger2: designing scopes, components, modules

左心房为你撑大大i 提交于 2019-12-25 06:35:17
问题 I'm using dagger 2 in a multi-layered , multi-library Android SDK project. I'm developing many different libraries on different layers (data, business logic, presentation etc...) and using dagger to glue them together. My most important requirement is that each library of the architecture should be usable stand-alone (with its dependent components) and that a developer should decide to build on top on any layer he wants: for example: rewrite all the presentation layer using everything below

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

偶尔善良 提交于 2019-12-25 03:02:38
问题 I am following the architecture used by GithubBrowserSample by Google. But facing troubles while building the project. I have migrated the project to AndroidX. I have tried many answers available on StackOverflow without success. Here is the build exception I am facing while building: e:/windows/Apps/Verifi/VerifiApp/app/build/tmp/kapt3/stubs/debug/com/verifi/di/component/AppComponent.java:11: error: [Dagger/MissingBinding] [dagger.android.AndroidInjector.inject(T)] java.util.Map<java.lang

How do I fix Dagger 2 error '… cannot be provided […]'?

橙三吉。 提交于 2019-12-25 01:55:45
问题 This is a Canonical Question because this is a common error with Dagger 2. If your question was flagged as a duplicate please read this post carefully and make sure to understand what this error means and why it occured. If this post does not work for you make sure to include where and how you provide the mentioned classes and include the full error message in your question like the one here. I tried to use a dependency with Dagger 2, but I receive the following error when I try to compile my

Integrating multi scope dagger 2 components

纵然是瞬间 提交于 2019-12-24 17:43:36
问题 Preconditions I have the following components: ApplicationCompoennt - With @ApplicationScope - This component contains LogModule. The logmodule @Provides Logger. ActivityComponent with @ActivityScope - This component contains MyActivityModule. Since one can't call the ctor of Activity explicitly, this module is used to inject the activity. This component depends on @ApplicationScope component, to use the Logger. BroadcastComponent with @BroadcastReceiverScope - This component contains

adding kotlin-kapt cause of getting Can not resolve symbol DaggerApplicationComponent error

假如想象 提交于 2019-12-24 10:24:10
问题 I did not already have any problem with Dagger as far i don't add Realm in my project, after adding that on my project i expect i can build successful my project but i get this error now: Can not resolve symbol DaggerApplicationComponent i want to need Realm on my application and i can't remove that, but i dont get any other error on Logcat to know whats problem and i should be fix that and I'm not sure how can i resolve this problem when i have this lines in build.gradle i dont have problem

Dagger 2: inject after define subcomponent

时光怂恿深爱的人放手 提交于 2019-12-24 09:13:06
问题 I follow this guide for making sub components for my Android application. Here I defined one sub component named LoginComponent used for LoginActivity: @Subcomponent(modules = LoginModule.class) public interface LoginComponent { void inject(LoginActivity activity); @Subcomponent.Builder interface Builder { Builder requestModule(LoginModule module); LoginComponent build(); } } @Module public class LoginModule { @Provides LoginManager provideLoginManager(LoginManagerImpl manager) { return

Dagger2 and qualifiers in dependent components

折月煮酒 提交于 2019-12-24 06:33:51
问题 I have an app component and a dependent component. The app component declares explicit dependencies, and the dependent component can inject those. However, when I have a dependency that I have to disambiguate with a @Qualifier, the dependent component is not able to inject that dependency. This is the app component @Component(modules = [AppModule::class, SchedulersModule::class, StorageModule::class]) @ApplicationScope interface AppComponent { fun inject(app: Application) /* other stuff

Dagger 2 - How does marking a class constructor with @Inject without component registration work

冷暖自知 提交于 2019-12-24 00:51:42
问题 i have dagger already set up with two components. One component is a subcomponent of another, big deal. Everything works. But then i randomly wanted to try constructor injection so i created a random class and marked its constructor with the Inject annotation and to my surprise when i wnated to inject this class it works ? my Component(s) know nothing about this. I have no written in my components interface about this class. its just a random class that has a constructor annotated with

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

Best Scope in Dagger2 for Okhttp3 with dynamic Interceptors

萝らか妹 提交于 2019-12-23 20:03:12
问题 How would the scope work with Auth Tokens? I cannot create my Retrofit instance until I can add an interceptor that signs it with my auth token. Therefore, I would like to create Retrofit when the auth tokens are available (after sign-in). How do I get scope working correctly in this situation? Thanks a lot! 回答1: There is no best way of doing this, and it might also depend on how often you change / recreate your Retrofit instances. What's better, or which better fits your use case depends