dagger-2

Dagger2 dependency - Gradle

老子叫甜甜 提交于 2019-12-18 10:07:28
问题 I'm trying to add Dagger2 to my project in Android Studio but I can't find proper dependency to paste in build.gradle. Could you help and send me the proper line? 回答1: Installing Dagger 2 on Android Studio 2 // Application build.gradle dependencies { compile 'com.google.dagger:dagger:2.4' annotationProcessor "com.google.dagger:dagger-compiler:2.4" } Maven Repositories: Find the latest versions of the above dependencies in the Maven Repository: dagger dagger-compiler Notes: Android Studio < 2

Cannot create an instance of custom ViewModel

孤人 提交于 2019-12-18 05:42:17
问题 I am using dagger2 library. whenever I am trying to run my project is says not able to create instance of view model class. main activity where I am trying to create an instance ((MovieApplication) getApplication()).getAppComponent().inject(this); mViewModel = ViewModelProviders.of(this).get(MoviesDataViewModel.class); My factory class public class ViewModelFactory implements ViewModelProvider.Factory { private MoviesDataViewModel mViewModel; @Inject public ViewModelFactory

Dagger 2: Provide same instance between multiple Component with same Scope on different library modules

懵懂的女人 提交于 2019-12-18 03:54:58
问题 I have a Core Android Library where I'm defining a CoreComponent ad using the @Singleton scope to inject instances of classes provided by a CoreModule. @Singleton @Component(modules = {CoreModule.class}) public interface CoreComponent { void inject(SomeClass target); } @Module public class CoreModule { @Singleton @Provides CoreRepository provideCoreRepository() { return new CoreRepositoryImpl(); } } I would like to access the same @Singleton instances from another Android Library that is

How do I use AndroidInjection class in custom views or other android classes?

与世无争的帅哥 提交于 2019-12-17 23:30:21
问题 My issue with the Android-specific pattern is, if you use their AndroidInjection class, there is no way to members inject other objects besides Activities / Fragments /custom views/adapters, except with the Application Component. This is because you cannot get a reference the the Subcomponent ( AndroidInjector ) used to inject Activities / Fragments . This makes injecting Dialogs (if you use DialogFragments ). The AndroidInjection class seems to support just the core Android types. 回答1: What

How do I configure IntelliJ/gradle to use dagger 2.0

梦想的初衷 提交于 2019-12-17 22:45:00
问题 I have a gradle project and I want to use dagger 2.0 in it. I don't know how to configure IntelliJ and gradle to generate files and let IntelliJ find them? My build.gradle file looks like: apply plugin: 'java' apply plugin: 'idea' version = '1.0' repositories { mavenCentral() maven { url "https://oss.sonatype.org/content/repositories/snapshots" } } dependencies { compile 'org.slf4j:slf4j-api:1.7.12' compile 'org.slf4j:slf4j-simple:1.7.12' compile 'commons-configuration:commons-configuration:1

How to make Jersey work with Dagger dependency injection?

流过昼夜 提交于 2019-12-17 20:18:05
问题 Jersey normally uses HK2 dependency injection, but I would like to use Jersey with Dagger 2. Both Dagger and HK2 implement JSR 330, which I have taken as evidence that this should be possible without too much effort. I found ways to make Jersey work with CDI (e.g. Weld), Spring DI and Guice, but I can't find anything on Dagger. To provide some context: I'm running a Grizzly–Jersey server in an SE environment, not in an EE container. My Maven project has com.google.dagger:dagger and org

Kotlin + Dagger - inject Map for ViewModel factory

坚强是说给别人听的谎言 提交于 2019-12-17 18:24:39
问题 I'm using the new Architecture Components with Dagger2 and I would like to inject my ViewModels using a Factory class. The Factory class is itself injectable. This all works well when the Factory class is defined in Java, but when I convert it to Kotlin, Dagger2 does not know how to generate the Map for the constructor, while in Java it knows how to do so. I presume the difference is that, after conversion, the Factory class uses the Map from the kotlin package, as opposed to from java.util

How to catch the Exception in Retrofit android

江枫思渺然 提交于 2019-12-13 20:30:46
问题 I have defined the classes as below. I have used dagger with Retrofit here What I am trying to do :: I am trying to catch the OfflineException in the request below how to catch it in Main Activity properly. RequestInterceptor.java public class RequestInterceptor implements Interceptor { ConnectivityManager connectivityManager; Application mApplication; @Inject public RequestInterceptor(Application mApplication) { this.mApplication = mApplication; connectivityManager = (ConnectivityManager)

error: cannot find symbol method contextModule(ContextModule)

徘徊边缘 提交于 2019-12-13 20:30:18
问题 I am developing news app but I am getting the following error from Logcat error: cannot find symbol method contextModule(ContextModule) below screenshot of error screenshot of error below BBCFragment.java class public class BBCSportFragment extends Fragment implements ArticleAdapter.ClickListener { public List<Article> articleList = new ArrayList<>(); @ActivityContext public Context activityContext; @ApplicationContext public Context mContext; @BindView(R.id.recycler_view) RecyclerView

Pass Context or Activity to adapter using Dagger 2

假如想象 提交于 2019-12-13 17:42:59
问题 I inject an Adapter using Dagger 2 without context and it is working, but I am not able to do when I am passing context parameter. Error is coming like this error: android.content.Context cannot be provided without an @Provides-annotated method. Dagger Component @PerActivity @Component(dependencies = ApplicationComponent.class, modules = MainFragmentModule.class) public interface MainFragmentComponent { void inject(MainFragment mainFragment); @ActivityContext Context provideContext(); }