title: Using CDI + WS/RS + JPA to build an app
body: <pre><code>@Path(value = "/user")
  @Stateless
  public class UserService {
  
      @Inject
      private UserManager manager;
  
      @Path(value = "/create")
      @GET
      @Produces(value = MediaType.TEXT_PLAIN)
      public String doCreate(@QueryParam(value = "name") String name) {
          manager.createUser(name);
  
          return "OK";
      }
  }
  </code></pre>
  
  <p>here is the user manager impl </p>
  
  <pre><code>public class UserManager {
  
      @PersistenceContext(unitName = "shop")
      private EntityManager em;
  
      public void createUser(String name) {
          User user = new User();
          user.setName(name);
          // skip some more initializations 
          em.persist(user);
      }
  }
  </code></pre>
  
  <p>the problem is if i do not mark UserService as @Stateless then the manager field is null </p>
  
  <p>but if i mark @Stateless, i can have the manager field injected, and the application works as i can get the data saved into db </p>
  
  <p>just wondering, what is the reason behind this? </p>
  
  <p>and is this the preferred way to wiring the application? </p>
  
  <p>well, i am thinking to pull out the EntityManager to a producer, so that it can be shared</p>