So I ran into a problem where I wanted to do some dependency injection inside a Android Service. I initialy thought we could do constructor injection just like any other class. However, that is not is the case. Thanks to THIS stackoverflow question and looking at the services of several open source Android projects, I have learned that we must do dependency injection into a Service like so:
@AndroidEntryPoint
class BillingService: Service() {
@Inject lateinit var billingClientWrapper: BillingClientWrapper
}
Note how the Service is annotated with @AndroidEntryPoint and we add @Inject lateinit to whatever we want to inject.
Conclusion
Thank you for taking the time out of your day to read this blog post of mine. If you have any questions or concerns please comment below or reach out to me on Twitter.
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)