Recently I started digging into the concept of Repository Patterns and UnitOfWork together with exploring the EntityFramework.
Made my own implementation based on an MVC example, where they were disposing the UnitOfWork from the Controller like so:
protected override void Dispose(bool disposing)
{
unitOfWork.Dispose();
base.Dispose(disposing);
}
I'm not into MVC at all, and pretty new in Webforms as well, but I assume they are overriding the Controller dispose method in order to dispose the UnitOfWork as "everything" else is disposed.
Basically I'd like to implement the same concept in my ASP.NET WebForms website and dispose the UnitOfWork that is used behind a Page's code together with the disposing of the Page itself.
I considered adding the same to the Page_Unload event from the life cycle, but I wasn't sure if this is the proper way to do it as I haven't messed with such things before. My idea as follows:
protected void Page_Unload(object sender, EventArgs e)
{
unitOfWork.Dispose();
base.Dispose();
}
How can I achieve that safely, and am I on the right track?