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 8361605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:44:09+00:00 2026-06-09T11:44:09+00:00

Cheers!I have some doubts about using Unit of Work with Repository. Specially a role

  • 0

Cheers!I have some doubts about using Unit of Work with Repository. Specially a role of child context from Entity Framework.
I have searched a lot of information about this theme, but all that I found just different types of using patterns, I’m confused and I can’t understand main think.

1.Where I should realize disposing and saving?
-Is it correctly realize Disposable in Inheritance class of DbContext?
After that realize in Repository and Unit of Work or just in Uni fo Work?

-Where put method Save in Unit of Work or Repository?

My repository will be Generic
Is my code is correct in architect style and other details?Please tell if my thinks are wrong.

    interface IRepository : IDisposable
    {
        void Create();
        void Delete();
        void Update();
        void Get();
        T getSomeByExpression()
        ...Some another costum operations
        ...should I remember about Save here? 
    }

    class Repository : IRepository
    {
        SomeContext context = new SomeContext();
        ...Using using(context = new SomeContext()){} in functions??
        ... 
        ....Disposing?
    }

    interface IUnitOfWork : IDisposable
    {
     ...Which methods I should realize?
    Commit()
    Save()
    ...Need some another methods like rollback, Attach() Add() or Dispose or something else?
    }
    class UnitOfWork
    {
     ...Collection of Repository

    }

Use after Unit of Work on Logic level?
Please help me to understand this theme.

I want know, how correctly use Unit Of Work and Repository patterns together, especially include DBContext.Also I want know where use some operations like Dispose.
Which operations should be in UnitOfWork commonly, Save etc.
How disposing context in repository?

  • 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-09T11:44:10+00:00Added an answer on June 9, 2026 at 11:44 am

    Here’s a great article on implementing unit of work using MVC.

    I normally dispose of the unit once the business transaction is complete. For example, if the action was to create a Parent, some children and attached them I dispose immediately once that is finished.

    Added more detail relating to above:

    In rereading your question, it sounds like you want more information about the theory of a unit of work rather than actual implementation, my apologies.

    Here’s a better article on MSDN related to that, but I will summarize for you.

    According to Martin Fowler, the Unit of Work pattern “maintains a list
    of objects affected by a business transaction and coordinates the
    writing out of changes and the resolution of concurrency problems.”

    Generally, I use the unit of work pattern to bring together all of the related repositories, to solve concurrency issues while still keeping the repositories separate.

    One of the best ways to use the Unit of Work pattern is to allow
    disparate classes and services to take part in a single logical
    transaction. The key point here is that you want the disparate classes
    and services to remain ignorant of each other while being able to
    enlist in a single transaction.

    • “Where I should realize disposing and saving?”

    I’m not sure I fully understand your question, but I think you’re asking what should be managing the lifecycle of the unit of work?

    Here’s another SO post related to this, but the summary is whatever owns the unit of work for the moment, and it’s related to how you setup the scope of your unit of work. For example, It can be the business command, or an MVC action.

    • “Is it correctly realize Disposable in Inheritance class of DbContext? After that realize in Repository and Unit of Work or just in Uni fo Work?”

    Do you mean, where should you be disposing of the DbContext? I believe that it should be in the unit of work. If you’re creating/disposing of multiple contexts in a single unit of work, maybe you should separate them out into 2 different units.

    • Where put method Save in Unit of Work or Repository?

    Your unit of work is handle the context, and the transactions, and should contain the logic to prevent duplicate updates, because of this your save function should be controlled by your unit of work.

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

Sidebar

Related Questions

I'm begginer in asp.net mvc and i have some doubts. P.S: I'm using DDD
morning I have some doubts about the the way php works. I cant find
I have some data being pulled in from an Entity model. This contains attributes
I need to make a mapping One by One, and I have some doubts.
Does anyone have some sample code of using a castle windsor InstallerFactory for ordering
I've been developing an application using asp.net MVC, and I have some configurations that
I have some code that works and changes the style sheet using a form.
Just wanna confirm my thoughts about CryptographicException on decryption. I have some tests, exactly
I have some Python code that uses Paramiko to grab build files from a
I have some code in a common library to support internationalization. The basic idea

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.