As I was learning ASP.NET on Youtube, an author created an instance of DBContext
by creating private variable of type DBContext
and initialize it to public constructor of a class:
public class CustomerController : Controller
{
private ApplicationDbContext context;
public CustomerController()
{
context = new ApplicationDbContext();
}
}
So, my question is would it be the same if I just create private instance of DBContext
, that is,
private ApplicationDbContext = new ApplicationDbContext();
Please can you explain why the author decided to create instance of DBContext
as shown above and what is the benefit of it.