title: My DbContext in RequestScope using Ninject throw: "The operation cannot be completed because DbContext the has been disposed."
body: <p>I have a Filter and a Filter Provider set in that way:</p>
  
  <pre><code>public class AuditoriaFilter : IActionFilter
  {
      #region Fields
  
      private readonly IRegistrarAuditoriaService _registrarAuditoriaService;
  
      private readonly IUsuarioRepository _usuarioRepository;
  
      private readonly ISiteRepository _siteRepository;
  
      private readonly IModuloRepository _moduloRepository;
  
      private readonly IAtividadeRepository _atividadeRepository;
  
      #endregion
  
      #region Constructors
  
      public AuditoriaFilter(IRegistrarAuditoriaService registrarAuditoriaService, IUsuarioRepository usuarioRepository, ISiteRepository siteRepository, IModuloRepository moduloRepository, IAtividadeRepository atividadeRepository)
      {
          this._registrarAuditoriaService = registrarAuditoriaService;
          this._usuarioRepository = usuarioRepository;
          this._siteRepository = siteRepository;
          this._moduloRepository = moduloRepository;
          this._atividadeRepository = atividadeRepository;
      }
  
      #endregion
  
      public void OnActionExecuted(ActionExecutedContext context)
      {
          Usuario usuario = _usuarioRepository.GetById(1);
  
          Site site = _siteRepository.GetById(1);
  
          Modulo modulo = _moduloRepository.GetById(1);
  
          Atividade atividade = _atividadeRepository.GetById(1);
  
          _registrarAuditoriaService.Registrar(usuario, site, modulo, atividade);
      }
  
      public void OnActionExecuting(ActionExecutingContext filterContext)
      {
      }
  }
  </code></pre>
  
  <p>Filter Provider:</p>
  
  <pre><code>public class AuditoriaFilterProvider : IFilterProvider
  {
      #region Fields
  
      private readonly IRegistrarAuditoriaService _registrarAuditoriaService;
  
      private readonly IUsuarioRepository _usuarioRepository;
  
      private readonly ISiteRepository _siteRepository;
  
      private readonly IModuloRepository _moduloRepository;
  
      private readonly IAtividadeRepository _atividadeRepository;
  
      #endregion
  
      #region Constructors
  
      public AuditoriaFilterProvider(IRegistrarAuditoriaService registrarAuditoriaService, IUsuarioRepository usuarioRepository, ISiteRepository siteRepository, IModuloRepository moduloRepository, IAtividadeRepository atividadeRepository)
      {
          this._registrarAuditoriaService = registrarAuditoriaService;
          this._usuarioRepository = usuarioRepository;
          this._siteRepository = siteRepository;
          this._moduloRepository = moduloRepository;
          this._atividadeRepository = atividadeRepository;
      }
  
      #endregion
  
      public IEnumerable&lt;Filter&gt; GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
      {
          bool postHttpMethod = controllerContext.RequestContext.HttpContext.Request.HttpMethod.ToUpper() == "POST";
          string controllerName = actionDescriptor.ControllerDescriptor.ControllerName;
  
          if (postHttpMethod &amp;&amp; controllerName != "Login")
              yield return new Filter(new AuditoriaFilter(_registrarAuditoriaService, _usuarioRepository, _siteRepository, _moduloRepository, _atividadeRepository), FilterScope.Action, null);
  
          yield break;
      }
  }
  </code></pre>
  
  <p>Global.asax:</p>
  
  <pre><code>public static void RegisterGlobalFilters(GlobalFilterCollection filters)
  {
      AuditoriaFilterProvider auditoriaFilterProvider = new AuditoriaFilterProvider(DependencyResolver.Get&lt;IRegistrarAuditoriaService&gt;(), DependencyResolver.Get&lt;IUsuarioRepository&gt;(), DependencyResolver.Get&lt;ISiteRepository&gt;(), DependencyResolver.Get&lt;IModuloRepository&gt;(), DependencyResolver.Get&lt;IAtividadeRepository&gt;());
  
      FilterProviders.Providers.Add(auditoriaFilterProvider);
  }
  </code></pre>
  
  <p>All my Ninject settings are the same way and are ok, only the <code>DbContext</code> is different: it is <code>InRequestScope()</code>:</p>
  
  <pre><code>public override void Load()
  {
      Bind&lt;IDbContext&gt;().To&lt;DbContext&gt;().InRequestScope().WithConstructorArgument("connectionString", ConfigurationManager.AppSettings["DefaultConnectionString"]);
  }
  </code></pre>
  
  <p>If I put the <code>DbContext</code> in <code>InSingletonScope()</code> all works ok, but <code>DbContext</code> can not stay in SingletonScope, it must to be in RequestScope.</p>
  
  <p>All controllers which depends on DbContext works fine when DbContext is InRequestScope, but when is time to .Net use the Filter it works only on the first Request, on the second request a exception is throw: <strong>"The operation cannot be completed because DbContext the has been disposed."</strong></p>