dagger-2

Dagger 2 - Why is this a dependency cycle?

巧了我就是萌 提交于 2019-12-08 15:40:33
问题 I'm trying to inject the application's Context into 2 other objects, an AuthManager and an ApiClient . Both of them depends on said context, and the ApiClient depends on the AuthManager . Why is this a dependency cycle, if Context doesn't have a reference to the others 2? can this be solved? EDIT: here is some code @Module public class AppModule { private final Application application; public AppModule(Application application) { this.application = application; } @Provides @Singleton Context

Dagger2 different scope modules injection not working fine while passing value from one class to another class

非 Y 不嫁゛ 提交于 2019-12-08 13:31:27
问题 I am playing with Dagger2 framework at android platform. I have imported my code at GitHub . While injecting more than 2 different modules at My ScreenA class , all the dependencies are injecting properly. But, while I am passing param from Screen A to Screen B and consuming parsed param at Screen B inner class ,all the injected modules instance becomes null. Screen A source codes : @Layout(R.layout.screen_a) public class ScreenA extends Path implements ScreenComponentFactory<MainActivity

How do you define dagger components and modules in tests?

断了今生、忘了曾经 提交于 2019-12-08 11:53:30
问题 I'm trying to create dagger 2 components and/or modules in test classes. This is to create (test) components to test individual production modules without having to have those superfluous components in the main build path. I find that Dagger 2 doesn't detect declarations under test. How do you configure that in gradle? See the example below (which doesn't reference anything in main) - (btw setting testAnnotationProcessor 'com.google.dagger:dagger-compiler:2.24' doesn't help). @RunWith

Dagger2 one module for two different scopes

走远了吗. 提交于 2019-12-08 08:17:35
问题 In my app i have an ApplicationScope which provides me with stuff like context and shared prefs. 2 sub components, LoggedInComponent and LoggedOutComponent. Those 2 subcomponents have other subcomponents which are less relevant to the issue. I have a NetworkModule which creates my retrofit instance. Both subcomponents need the NetworkModule but the retrofit might change during the login because the base url and other settings might change. I was wondering which approach it is better to take:

Kodein vs Dagger - Can't Get Dagger Working w/ Multiple Modules

微笑、不失礼 提交于 2019-12-08 06:03:58
问题 (x-post from /r/androiddev) I would just like to preface this by saying that this is not a "which is better" post; this is strictly a question about how I can build something using Dagger (and how I built it in Kodein to help illustrate the problem). I've been using Kodein for a few years now in several work projects, and I've found it to be so easy to work with, that I never look at Dagger anymore. I started a new personal project, and I thought I'd give Dagger another shot. To keep things

Can't inject same instance into a Service and a ViewModel

走远了吗. 提交于 2019-12-08 05:38:51
问题 I am trying to replicate this this Singleton using Dagger 2. I would like to have a BehaviorSubject in which I call onNext() to in a service and subscribe() to in a ViewModel. Here is my Singleton object: object MyMessageBus { val pusher = BehaviorSubject.create<String>() } In my Service I can do this: private val pusherObservable = MyMessageBus.pusher override fun onCreate() { super.onCreate() println("service myObservable = ${pusherObservable.hashCode()}") } and then in my ViewModel I can

Dagger 2 Scopes, where to place Presenters?

偶尔善良 提交于 2019-12-08 04:05:22
问题 what would it be the best practice about placing Presenters in a Scope? Could we have Presenters on @Singleton or @AppScope without any problem? Should they be placed in an @ActivityScope in order to destroy them each time the activity is destroyed? 回答1: what would it be the best practice about placing Presenters in a Scope? Usually a presenter should be in some scope. Not placing it in any scope will lead to problems, as every time you request a presenter it would create a new one. Which

Espresso testing with Dagger 2 and custom scopes

拥有回忆 提交于 2019-12-08 02:05:43
问题 After a recent migration to Dagger 2, the app I am working on is using an @ActivityScope for every feature. Each app feature is implemented using MVP pattern and has it's own local dagger Component setup which depends on the Application component for the dependencies that are required during the entire app lifecycle (provided by the App). Each feature’s Activity extends a base class which provides the main application component to a method that is overridden by each activity in order to set

PowerMock + Robolectric + Dagger2

末鹿安然 提交于 2019-12-08 00:25:35
问题 I test custom view class which contain: android ui elements some logic static methods callings dagger2 dependencies So i use next tools for testing Robolectric for UI elements mocking unit tests for logic testing PowerMock for static methods mocking Robolectric + PowerMock integration problem is known and solution is known - https://github.com/robolectric/robolectric/wiki/Using-PowerMock But with this solution dagger2 dependencies fail. Attention to code. My custom view: public class

Dagger 2 - injecting multiple objects of same type using @Named not working

ε祈祈猫儿з 提交于 2019-12-07 19:37:37
问题 My module: @Module public class TcpManagerModule { private ITcpConnection eventsTcpConnection; private ITcpConnection commandsTcpConnection; public TcpManagerModule(Context context) { eventsTcpConnection = new EventsTcpConnection(context); commandsTcpConnection = new CommandsTcpConnection(context); } @Provides @Named("events") public ITcpConnection provideEventsTcpConnection() { return eventsTcpConnection; } @Provides @Named("commands") public ITcpConnection provideCommandsTcpConnection() {