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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:31:49+00:00 2026-06-05T11:31:49+00:00

Normally the code for using the dbContext from Entity Framework looks something like this:

  • 0

Normally the code for using the dbContext from Entity Framework looks something like this:

using (var context = new SMDbContext())
{
    context.StartTransaction();

    var userCrudLogic = new UserEntityCrudLogic(context);
    userCrudLogic.CreateUser(...);

    context.SaveChanges();
    context.Commit();
}

In my case I want to use this in a web service, and instead of calling my CRUD logic I would like to call a business logic to do some validation and other things. The business logic afterwards will call the CRUD logic.

My problem is that I don’t know how to store or pass the context to the CRUD logic. The easiest way would be to use a parameter but I don’t want to have a unneeded parameter in all my business logic functions.

I think it would be better to have something like an “context manager” which is responsible for storing and providing the context for the current request. Than I could use IoC or something like that to load the context wherever its needed.

But how should such a “manager” look like and how/where I have to store it?

If I register it in IoC as singleton (in global.asax), will it be shared over all requests or is it unique for each?

Sorry if my question seems stupid or something like that, but I have never done such things before and want to learn them now! So I don’t want to just make it working, I want to know what the best way to do it. If something is unclear, please just ask!

Greetings

  • 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-05T11:31:51+00:00Added an answer on June 5, 2026 at 11:31 am

    You probably must configure your web application with a context per request. Do a google and you’ll get something like this Caching Entity Framework DbContexts per request and One DbContext per request in ASP.NET MVC (without IOC container)

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

Sidebar

Related Questions

Let me explain using this code sample: var commands1 = new List<int> { 1
It appears like something is stopping my errors from displaying normally an in ASP.NET
I'm using this code to return some string from a tcpclient but when the
I am using Entity Framework code first and ASP.NET MVC 3. I have the
Using code to hook the console close event from this thread , I sometimes
I'm using Entity Framework 4.1 Code First and I have a table that has
I normally code on windows and using MYSQL4.1. And mysql gem version is 2.8.1.
This kind of code would normally work in PHP, but since the scope is
I normally use the following code in SQL Server: IF EXISTS (SELECT * FROM
I wrote this code. The constructor works normally, but in the destructor I get

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.