dagger-2

Dagger and mvp - should presenter use dagger for injection

时光毁灭记忆、已成空白 提交于 2019-12-11 04:08:14
问题 I'm starting to think in mvp, dagger should not be used in the presenter. The usual way to construct dagger is using a global component and have subcomponents for scoping the graph. This global component will take an applicationContext as a parameter on creating the appmodule.java class usually. Having the application context given makes life easier. That's all fine but if I use a module from the global component or even a subcomponent, the context should be passed in. So that means if I

Android Dagger 2 with BaseActivity to reduce boilerplate

落花浮王杯 提交于 2019-12-11 03:51:16
问题 I'm having some troubles while I want to move some Dagger 2 boilerplate code in each activity to a BaseActivity. BaseActivity extends AppCompatActivity I have multiples activities, like: ActivityA extends BaseActivity implements InterfaceA; ActivityB extends BaseActivity implements InterfaceB; ... In each activity I have a methods like this (where X is A, B, C, ... for each activity): public void initActivity() { ComponentX compX; ... compX = appComponent.plus(new ModuleX(this)); // this ==

How to declare dependencies

我只是一个虾纸丫 提交于 2019-12-11 03:04:11
问题 I'm studying Dagger 2 so I would like to understand some basic things. I have the following code: @Module public class MainModule { @Provides public Presenter provideMainActivityPresenter(Model model){ return new MainPresenter(model); } @Provides public Model provideMainModel(){ return new MainModel(); } } and my MainPresenter class looks like this: public class MainPresenter implements Presenter { @Nullable private ViewImpl view; private Model model; public MainPresenter(Model model) { this

Dagger 2 not injecting sharedPreference

こ雲淡風輕ζ 提交于 2019-12-11 02:43:59
问题 Hi i am new to dagger 2 and trying to inject an instance of sharedPreference inside my MyActivity class below: class MyApplication : Application() { companion object { @JvmStatic lateinit var applicationComponent : ApplicationComponent } override fun onCreate() { super.onCreate() applicationComponent = DaggerApplicationComponent.builder().androidModule(AndroidModule(this)).build() } } Here is the component and modules @Singleton @Component(modules = arrayOf(AndroidModule::class)) interface

Dagger component dependency meaning

隐身守侯 提交于 2019-12-11 02:37:40
问题 I'm experimenting with Dagger 2 and I'm just testing things out to understand the framework. I'm having a ApplicationComponent that needs to be a singleton for the whole app so I defined it like this: @Component(modules = {ApplicationModule.class}) @Singleton public interface ApplicationComponent { Context provideContext(); } With module: @Module public class ApplicationModule { private Application appContext; public ApplicationModule(Application appContext) { this.appContext = appContext; }

Inject presenter into activity via Dagger

折月煮酒 提交于 2019-12-11 00:56:36
问题 I want to know how to inject Presenter in activity using code Following are details Following is error message: Error:(12, 46) error: cannot find symbol class DaggerCategoryPresenterComponent Error:(9, 46) error: cannot find symbol class DaggerNetComponent Error:(18, 10) error: [Dagger/MissingBinding] com.headytest.android.category_listing.CategoryContract.CategoryPresenter cannot be provided without an @Provides-annotated method. com.headytest.android.category_listing.CategoryContract

GoogleApiClient must not be null [Awareness API]

跟風遠走 提交于 2019-12-10 23:26:53
问题 I'm trying to find out why the Google Play Services is crashing with a nullpointerexception after the application is coming back from a background state such as device sleep or toggle other program. Sometimes Google Play Services gives the crash popup on application start. So I assume the problem lies somewhere on the path to the service since there is where the threading occurs with rxjava. Note: I Inject GoogleApiClient in both MainActivity (field injection) and in GoogleApiService

Dagger2 difference between modules and dependincies

烈酒焚心 提交于 2019-12-10 22:22:54
问题 I am failing to understand the difference between telling a component what are his modules and telling the component what are its component dependencies. For example: @Module public class ModuleA { @Provides DependencyA providesDependencyA() { return new DependencyA(); } } @Module public class ModuleB { @Provides DependencyB providesDependencyB() { return new DependencyB(); } } @Component (modules = {ModuleA.class}) public interface ComponentA { DependencyA getDependencyA(); } what is the

from one dagger2 module how to access the SharedPreferences provided in another dagger2 module

谁说胖子不能爱 提交于 2019-12-10 22:17:01
问题 Having the SharedPreferences provided from one dagger2 module, in another dagger2 module would like to use it, how to do it? the code below seems not working. /** the component */ @Singleton @Component(modules = arrayOf(DataManagerModule::class, AnotherModule::class)) interface DataManagerComponent { fun getDataManager() : DataManager fun getSharedPreferences() : SharedPreferences } /** the module 1 */ @Module class DataManagerModule(@ApplicationContext private val appContext: Context) {

Static provide method in Dagger2

无人久伴 提交于 2019-12-10 18:33:45
问题 Why should use static modifier before the provide method? Even though I remove the static modifier, dagger2 works correctly. @Provides static Pump providePump(Thermosiphon pump) { return pump; } 回答1: Both styles work; whether you keep the method static is entirely up to you and your normal "should this be a static method" judgment in plain old Java. Here, pump doesn't have any use for a module instance, so the method can easily be static. Static method calls are faster, particularly in