title: jersey + grizzly + hk2: Dependency injection, but not into resource
body: <p>Following up on <a href="https://stackoverflow.com/questions/19081840/jersey-hk2-grizzly-proper-way-to-inject-entitymanager">Jersey + HK2 + Grizzly: Proper way to inject EntityManager?</a>, I would like to understand how it is possible use dependency injection in classes which are <em>not jersey resources</em>. </p>
  
  <p>As an example, I might have background tasks running in an ExecutorService, and they might need an EntityManager. If I attempt to <code>@Inject</code> the EntityManager into the class, nothing happens. Injecting it into a <code>@Path</code>-annotated jersey resource class, injecting works fine.</p>
  
  <p>The application is running as a standalone JVM, not on a Java EE application server.</p>
  
  <p><strong>Update:</strong> I have created a <a href="https://github.com/hankipanky/GrizzlyHk2Test" rel="noreferrer">test scenario</a> to demonstrate what I mean. The code is running a standalone Grizzly server with a Jersey resource, as well as an ExecutorService. A <code>Callable</code> is submitted to the ExecutorService.</p>
  
  <p>Injection of the EntityManager into the resource works, but not into the Callable. There the EntityManager remains <code>null</code>.</p>
  
  <p>Please advise if the code is better kept here than on github.</p>