1

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?

danb
  • 10,239
  • 14
  • 60
  • 76

1 Answers1

2

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.

danb
  • 10,239
  • 14
  • 60
  • 76
  • 1
    This is a good approach and arguably better than injecting the Application. However, this is currently a workaround of this bug: https://github.com/johncarl81/transfuse/issues/62 – John Ericksen Mar 06 '14 at 16:22