ASP.NET MVC and Idisposable
2 answers
This is not such a bad question as some might think. It just isn't right. Consider the following code:
ActionResult UserList()
{
using (var ctx = new DbCtx())
{
return View(ctx.Users)
}
}
Will not work as the ctx is located long before the view actually iterates over the data, resulting in an object being thrown.
The solution is to get rid of the ctx in the Controller. What's not obvious is that most of the dependencies introduced into our controllers will sooner or later have to implement IDisposable.
This is not a problem with mvc.
0
a source to share