Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8143275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:04:54+00:00 2026-06-06T13:04:54+00:00

Recently I started digging into the concept of Repository Patterns and UnitOfWork together with

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:04:55+00:00Added an answer on June 6, 2026 at 1:04 pm

    First of all: Don’t invent the wheel.

    Use Dependency Injection frameworks like: StructureMap, Ninject, Unity, etc….

    Your UoW should be started with beginning of a web request and disposed when the request is ended.

    In other words: DataContext of EF should be initialized when a request is started. Then you can store it somewhere(Session, …), and it can be reused for that request. One instance of DataContext per request.

    But if you try to do it yourself, you are in the wrong way, using a dependency injection framework, would make it so easy.

    The framework can handle lifetime of your DataContext(UoW).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently started digging into design patterns. Generally speaking, I thought the design issues
I recently started digging into C# but I can't by my life figure out
I recently started learning 0MQ . Earlier today, I ran into a blog, Python
I recently started with C++ and i'm not entirely sure I grasp the concept
I recently started tracking changes for my project with Mercurial. I made several revisions
I recently started using rvalue references and I've run into a case where I
I recently started looking into django and I started with the tutorial. I noticed
I recently started learning Python. Not yet ventured into coding. During one of my
I recently started using rspec and factory_girl and I'm working on a basic control
I recently started learning Objective-C, and I am working on an iOS app as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.