title: MVC3 Action Filter Using Database (EF 4.1 DBContext, Ninject)
body: <p>I'm trying to setup an 'Authorization' Filter on an Action, creating my own ActionFilterAttribute where I do a database lookup to determine if a user has access to a certain resource.</p>
  
  <p>On my class inheriting from ActionFilterAttribute, I have created an Injected(Ninject) property to hold the service that I am using for the database access.  I have a parameterless constructor so that I can use this as an attribute on my actions.  In the 'OnActionExecuting' Method, I am able to gain access to the Injected property (it's not null), but the base DBCotext that it is using is closed.</p>
  
  <p>This working fine, up until the RTM of MVC3, where the Release Notes stated:</p>
  
  <blockquote>
    <p><strong>Breaking Changes</strong>:
        In previous versions of ASP.NET MVC, action filters are create per
    request except in a few cases. This
    behavior was never a guaranteed
    behavior but merely an implementation
    detail and the contract for filters
    was to consider them stateless. In
    ASP.NET MVC 3, filters are cached more
    aggressively. Therefore, any custom
    action filters which improperly store
    instance state might be broken.</p>
  </blockquote>
  
  <p>The first time I use this filter, it works as expected, but if I refresh the page or another user access this filter, I get the error:</p>
  
  <blockquote>
    <p>The operation cannot be completed
    because the DbContext has been
    disposed.</p>
  </blockquote>
  
  <p>which is what I guess I should expect given the breaking changes notes.</p>
  
  <p>My question is this, what would be the preferred/recommended way of accomplishing what I need to do?  Should this be in an ActionFilterAttribute, or should this 'authorization' be done somewhere else?</p>