title: subresources problem with dependencies in JAVA
body: <p>When I created my subresource, my Injection (authenticatedUser) is null. But in the root class (authenticatedUser) the Injection had the correct values. Therefore, when I used </p>
  
  <blockquote>
    <p>/medicos/me</p>
  </blockquote>
  
  <p>I get the correct values, but when I used </p>
  
  <blockquote>
    <p>/medicos/me/pacientes</p>
  </blockquote>
  
  <p>I get a error null, from authenticatedUser in subresource PacienteResource.
  I don't understand and how I can resolve this dependency in sub resource. This dependency (authenticatedUser) is produced in authentification filter.</p>
  
  <pre><code>@Path("/medicos")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public class MedicoResource {
  
      @Inject
      @AuthenticatedUser
      Usuario authenticatedUser;
  
      @GET
      @Path("me")
      @Produces(MediaType.TEXT_PLAIN)
      public Response getMedico() {
          return Response.ok(authenticatedUser.getMedico().getNombre()).build();
      }
  
      @Path("/me/pacientes")
      public PacienteResource getMedicoPacientes() {
          System.out.println("get medico pacientes");
          return new PacienteResource();//This is the problem.
      }
  }
  </code></pre>
  
  <p>Subresource class also had the authenticatedUser, but when I used it, this is null.</p>
  
  <pre><code>public class PacienteResource {
  
      @Inject
      @AuthenticatedUser
      private Usuario authenticatedUser;
  
      @Inject
      PacienteService pacienteService;
  
      @GET
      @RolesAllowed({"MEDICO"})
      public Set&lt;Paciente&gt; getPacientes() {
          Set&lt;Paciente&gt; pacientes = authenticatedUser.getMedico().getPacienteSet();
          return pacientes;
      }
  }
  </code></pre>
  
  <p>This is my producer of @AuthenticatedUser. The filter "Authentification"throw a event, for this Observer "handleAuthenticationEvent". Then when I need a authenticatedUser I only should inject a @AuthenticatedUser. But when I created the new instance of pacienteResource, the AuthenticatedUser is not produced.</p>
  
  <pre><code>@RequestScoped
  public class AuthenticatedUserProducer {   
  
      @Inject
      private UsuarioService usuarioService;
  
      private Usuario authenticatedUser;
  
      public void handleAuthenticationEvent(@Observes @AuthenticatedUser String username) {
          this.authenticatedUser = findUser(username);
      }
  
      private Usuario findUser(String username) {
          Usuario usuario = usuarioService.findByUserName(username);
          return usuario;
      }
  
      @Produces
      @RequestScoped
      @AuthenticatedUser
      public Usuario createLogger() {
          return authenticatedUser;
      }
  }
  
  @Qualifier
  @Retention(RUNTIME)
  @Target({METHOD, FIELD, PARAMETER})
  public @interface AuthenticatedUser {
  
  }
  </code></pre>