title: Entity Framework Context in Singleton
body: <p>I'm building a App that use Context of EF in Singleton Pattern like NHibernate work with Session:</p>
  
  <pre><code>public class DbContextFactory
  {
      private static volatile DbContextFactory _dbContextFactory;
      private static readonly object SyncRoot = new Object();
      public DbContext Context;
  
      public static DbContextFactory Instance
      {
          get
          {
              if (_dbContextFactory == null)
              {
                  lock (SyncRoot)
                  {
                      if (_dbContextFactory == null)
                          _dbContextFactory = new DbContextFactory();
                  }
              }
              return _dbContextFactory;
          }
      }
  
      public DbContext GetOrCreateContext()
      {
          if (this.Context == null)
              this.Context = new DbContext(ConfigurationManager.AppSettings["DefaultConnectionString"]);
  
          return Context;
      }
  }
  </code></pre>
  
  <p>I'm using Ninject to Inject the Context:</p>
  
  <pre><code>public class DbContextModule : NinjectModule
  {
      public override void Load()
      {
          Bind&lt;IDbContext&gt;().ToConstant(DbContextFactory.Instance.GetOrCreateContext());
      }
  }
  </code></pre>
  
  <p>I'm reading about that approach and some people are saying that is bad practice and I'll have problems.</p>
  
  <p>Someone that know about this with EF can explain me in more details?</p>