Using AndroidInjector (Dagger 2.10) to inject a service inside a library

According to dagger.android we could use AndroidInjector

to inject any android component, in this case I want to inject a Service using either DaggerIntentService

or calling directly AndroidInjection.inject(this)

in my service. I understand that we need to install a subcomponent for the service, for example:

@Subcomponent(modules = ...)
public interface MyServiceSubcomponent extends AndroidInjector<MyService> {
  @Subcomponent.Builder
  public abstract class Builder extends AndroidInjector.Builder<MyService> {}
}

      

The question is, in all examples, in order to be able to user AndroidInject, we need to build the main component in the application and then Dagger will do the rest. My problem is that since mine Service

is inside a library project, I don't have a class Application

to add the final wiring these components need. This can be achieved with the usual Dagger2 setUp adding inject(MyService service)

to my library component and wiring directly on my onCreate, but I would like to use new components, is that possible?

+3
android dependency-injection dagger-2 androidinjector


source to share


No one has answered this question yet

Check out similar questions:

3178
AngularJS: Service vs provider vs factory
2947
What is dependency injection?
sixteen
Dagger 2.10 Android Subcomponents and Developers
3
Dagger2 does not generate Dagger classes *
2
Dagger and mvp - must use injection dagger for injection
2
Library attachment using a dagger
1
Dagger Dependency Injection 2
0
Dagger 2 does not generate subcomponent implementation
0
The dagger does not work for retrofitting
0
Dagger2 introduces null object



All Articles
Loading...
X
Show
Funny
Dev
Pics