title: Entity Framework generic repository life cycle
body: <p>I've read a couple of articles about creating a generic repository in Entity Framework. In every article the ObjectContext is passed as an argument to the constructor like this:</p>
  
  <pre><code>public Repository(ObjectContext context)
  {
      _context = context;
  }
  </code></pre>
  
  <p>In a web application the preferred way to handle ObjectContext lifestyle is per web request. This means that these repositories must also have lifestyle per web request, if used in in a web context. This spreads to services using repositories and further on if we stick to constructor injection...</p>
  
  <p>I think the ObjectContext life cycle should be handled outside the repositories, for example in a HttpModule. <strong>I would also like to handle repositories as singletons instead, and then ObjectContext can't be injected in the constructor.</strong> Another mechanism for getting the ObjectContext into the repository must be used, like an ObjectContextFactory.</p>
  
  <p><strong>Whats the downside of handling the repositories with a singleton lifestyle?</strong></p>