I'm working on a project somebody else developed. In the project, it has
public class HomeController : Controller
{
public HomeController() {
_EntitiesContext = new EntitiesContext();
_UsersContext = new UsersContext();
}
public UsersContext _UsersContext { get; set; }
public EntitiesContext _EntitiesContext { get; set; }
......
Then, whenever it needs query, it will use these context.
Usually, what I do is: I do not create these context in HomeController(), instead, I create them by using .... syntax whenever I need them. I think it will open connection, do the query, then close the connection. otherwise, the connection will be always open. If too many people use it, it may generate issues.
Am I correct on this? I think I read this online before, but could not find it anymore.
Thanks