每次在同一个请求中调用存储库时,在内部实例化DbContext有什么好处?
我应该这样做:
public class HomeController : Controller
{
public ActionResult Index()
{
var repo1 = new MyRepo1();
var repo2 = new MyRepo2();
var repo3 = new MyRepo3();
return View();
}
}
或者这个:
public class HomeController : Controller
{
MyContext db = new MyContext();
public ActionResult Index()
{
var repo1 = new MyRepo1(db);
var repo2 = new MyRepo2(db);
var repo3 = new MyRepo3(db);
return View();
}
}