我目前正在用Unity和Entity框架構建ASP.NET MVC應用程序。我使用Unity MVC 3安裝程序,它使用ContainerControlledLifetimeManager來解析依賴關係(http://devtrends.co.uk/blog/introducing-the-unity.mvc3-nuget-package-to-reconcile-mvc3-unity -and-IDisposable的)。這工作正常,直到我嘗試啓動另一個線程,在加載頁面後執行耗時的任務,並且用戶收到更新。從線程,我得到這個錯誤:使用Unity與ThreadPool進行Dbcontext的LIfetime管理
The operation cannot be completed because the DbContext has been disposed.
我相信這是因爲主線程完成這樣的集裝箱和它的孩子們得到處理。有誰知道這個解決方案嗎?
謝謝!
你可以發佈你聲明和使用DbContext ..的代碼嗎? perhps你正在做一些使用(){} – MethodMan 2012-01-03 22:11:41
你注入一個上下文嗎?代碼在這裏請:) – 2012-01-03 22:50:37