title: Play framework 2.6 java websockets akka dependency injection
body: <p>I am using java websockets in play framework 2.6 and having hard time figuring out Guice DI. Below I am injecting DbService (which perform some db operations) but I am getting DbService as null and throwing NPE at line</p>
  
  <pre><code>User user = dbService.findByName(inEvent.getUsername());
  </code></pre>
  
  <p>dbService is null. I am not sure why its not injecting DbService. Although this work when I don't use it via akka actors. I do bind DbService to its implementation. </p>
  
  <p>Actor </p>
  
  <pre><code>public class TestActor extends AbstractActor {
     @Inject
     private DbService dbService;
  
     private ActorRef out;
  
     public static Props props(final ActorRef out) {
        return Props.create(TestActor.class, out);
     }
  
     public TestActor(ActorRef out) {
         this.out = out;
     }
  
     @Override
      public Receive createReceive() {
          return receiveBuilder()
            .match(InEvent.class, inEvent -&gt; {
                System.out.println(inEvent.getUsername());
                User user = dbService.findByName(inEvent.getUsername());
                System.out.println(user.getFirstName());
                out.tell("userName is ", self());
            }
              )
            .build();
      }
  
  }
  </code></pre>
  
  <p>Controller </p>
  
  <pre><code>public class Application extends Controller {
  
      public WebSocket TestWebSocket() {
          return WebSocket.json(InEvent.class).acceptOrResult(request -&gt; {
  
              final Token token = verifyToken(request());
              if (token == null) {
                  return CompletableFuture.completedFuture(F.Either.Left(forbidden()));
              }
  
              return CompletableFuture.completedFuture(
                      F.Either.Right(ActorFlow.actorRef(out -&gt; TestActor.props(out), actorSystem, materializer)));
  
          });
      }
  
  }
  </code></pre>