Create a private instance of your DBContext.

Within the controller constructor instantiate your DBContext.

Override the controllers Dispose method and dispose of your DBContext.

public class CustomerController : Controller
{
    private ApplicationDbContext _context;


    public CustomerController ()
    {
        _context = new ApplicationDbContext();
    }

    protected override void Dispose(bool disposing)
    {
        _context.Dispose();
    }
}
Copyright © 2025 delaney. All rights reserved.