title: @Inject a Morphia DAO with CDI?
body: <p>I'm writing a Java EE 6 application that makes use of Morphia to persist objects to MongoDB.  I'd like to be able to <code>@Inject</code> my DAO classes where necessary, so I created a Factory class that instantiates the DAO appropriately.  It looks something like this:</p>
  
  <pre><code>public class MyDAOFactory {
  
      @Inject
      private Datastore mongoDatastore = null;
  
      /**
       * Creates the DAO
       */
      @Produces
      @ApplicationScoped
      public MyDAO createDAO() {
          MyDAO dao = new MyDAO(
                  this.mongoDatastore);
          return dao;
      }
  }
  </code></pre>
  
  <p>The code compiles fine, but when I run my application on JBoss EAP 6.1 it complains because <code>MyDAO</code> does not have a no-arg constructor.  I would add one, but the Morphia BasicDAO class does not have one either, so I don't know that it would work that way.  </p>
  
  <p>Is there a way to <code>@Inject</code> a DAO instance into my EJB, Servlet, etc.?  Or do I need to manually instantiate it every time?</p>