What is the advantage of instantiating DbContext internally each time I call a repository in the same request?
Should I do this:
public class HomeController : Controller
{
public ActionResult Index()
{
var repo1 = new MyRepo1();
var repo2 = new MyRepo2();
var repo3 = new MyRepo3();
return View();
}
}
Or this:
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();
}
}