dagger-2

Android Dagger 2 POJO field Inject null

…衆ロ難τιáo~ 提交于 2020-01-02 04:07:15
问题 Just started using Dagger 2 today and I'm a bit confused on how exactly I need to set everything up. I'm trying to inject a POJO, but it's always null. First, some code: App.java private AppComponent appComponent; @Override public void onCreate() { super.onCreate(); appComponent = DaggerAppComponent .builder() .appModule(new AppModule(this)) .build(); } public AppComponent component() { return appComponent; } AppModule.java @Module public class AppModule { private Application app; public

How do you provide a GoogleApiClient dependency with Dagger2?

会有一股神秘感。 提交于 2020-01-02 02:41:10
问题 I've started using Dagger2 to manage dependencies and I'm trying to understand how I can use DI to provide a singleton GoogleApiClient. The motivations for this are: reduce boilerplate code : multiple Activities & Fragments require a GoogleApiClient improve testability : currently these Activities and Fragments are not well tested I want to provide a Singleton GoogleApiClient at the Application scope. How do you handle callbacks? Whether you choose an auto-managed or manually-managed

Is it possible to use dagger2 with jersey the same way it is possible with guice?

半世苍凉 提交于 2020-01-01 19:02:12
问题 Is it possible to use dagger2 with jersey the same way it is possible with guice? Is there any dagger2 servlet or dagger2 jersey project? 回答1: So, short answer is no, there is not a great way to do this while getting all of the features of Jersey in your application. However, there are ways to partially do this. You can simply register your resource in an application servlet ( see an example of that here https://github.com/cogman/gluews/blob/master/src/main/java/com/cogman/glue

Component (unscoped) may not reference scoped bindings

时光总嘲笑我的痴心妄想 提交于 2020-01-01 07:55:35
问题 I've recently started using dagger-2 with kotlin. Unfortunately I have ecnountered a problem with sumbcomponants and I have trouble understanding why I get this gradle error: ...NetComponent (unscoped) may not reference scoped bindings: @dagger.Subcomponent(modules = {com.example.kremik.cryptodroid.di.module.NetModule.class}) @Singleton @Provides com.example.kremik.cryptodroid.data.remote.CMCService com.example.kremik.cryptodroid.di.module.NetModule.providesCMCService(retrofit2.Retrofit)

Generating a MembersInjector for [Class]. Prefer to run the dagger processor over that class instead

好久不见. 提交于 2020-01-01 04:04:30
问题 I have these warnings and I don't understand what they mean. Can someone point me to something? For classes I inject into (where there is a component.inject(this) statement) Note: Generating a MembersInjector for [class] Prefer to run the dagger processor over that class instead. For object I am injecting (constuctor annotated with @Inject ) Note: Generating a Provider for [class]. Prefer to run the dagger processor over that class instead. 回答1: When Dagger's annotation processor runs, it

Generating a MembersInjector for [Class]. Prefer to run the dagger processor over that class instead

人走茶凉 提交于 2020-01-01 04:04:13
问题 I have these warnings and I don't understand what they mean. Can someone point me to something? For classes I inject into (where there is a component.inject(this) statement) Note: Generating a MembersInjector for [class] Prefer to run the dagger processor over that class instead. For object I am injecting (constuctor annotated with @Inject ) Note: Generating a Provider for [class]. Prefer to run the dagger processor over that class instead. 回答1: When Dagger's annotation processor runs, it

Building an Android Instant App with Application Component from Dagger

ⅰ亾dé卋堺 提交于 2020-01-01 03:58:05
问题 I'm currently experimenting with InstantApps and would like to include dagger into my project. I'm facing an issue setting up an application AppComponent. My application component includes all the feature dagger modules of my app. I basically have: One Base app module containing my Application class Multiple features with each a dagger Module per Activity, all with Base as a dependency. One app module and instant module both importing all the features and the base app module. I'm trying to

How to inject dependencies into any kind of object with Dagger2?

孤者浪人 提交于 2019-12-31 21:33:51
问题 According to http://konmik.github.io/snorkeling-with-dagger-2.html i could just add inject(Anything anything) into AppComponent.java, but this doesn't work for me, in the articles example: @Singleton @Component(modules = AppModule.class) public interface AppComponent { void inject(MainActivity activity); void inject(MainFragment fragment); void inject(MainToolbarView view); } If I try to inject dependencies into my fragment the injected members remain null. What obvious error am I missing

How to create custom scoped modules in dagger 2.10

独自空忆成欢 提交于 2019-12-30 09:54:14
问题 I am trying to migrate the company app to dagger 2.10 and the AndroidInjector.inject method, but I think I found a problem. The app uses custom scopes… like the feature Login has 3 activities (each one with it`s own dagger module) and one LoginModule that is responsible for sharing singletons that only should live in this scope. So in the first Activity I used to execute something like: public class LoginActivity extends AppCompatActivity{ public void onCreate(Bundle bla){

Dagger2 activity scope, how many modules/components do i need?

流过昼夜 提交于 2019-12-30 09:38:10
问题 I have a couple of questions about custom scopes: I'm using MVP architecutre and I need to inject different presenters to different activities. For that purpose I've created @ActivityScope. Does it mean that I must create a separate module/component for every activitiy? What is the purpose of custom scope annotations if I'm still responsible for creating and releasing those dependencies? Not sure if I'm right but I can use @Scope123 in all my modules/components and it won't make any