Question

How can I create a singleton that gets injected with an application context. Just annotating with @Singleton and then using @Inject on the constructor ends up generating an UnscopedProvider class that will not compile. How can I make an ApplicationScoped provider... or is there another mechanism to accomplish this?

Was it helpful?

Solution

The solution I ended on here is to create an init(Application app) {} method on the Singleton, then inject the Singleton into my @Application annotated class and call the init method using the Application that's injected into that class. I think this is the only way to do this currently.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top