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?
source to share
No one has answered this question yet
Check out similar questions: