1
votes

I have a asp.net web application that uses Entity Framework. The application data layer uses a method outlined by Jordan Van Gogh found here. In a nutshell, this method uses one shared objectcontext instance per http request and is disposed of using a AspNetObjectContextDisposalModule that inherits IHttpModule.

I have added another project, a few additional tables, and setup a data layer that copies (exactly) the example I described above to my application. This additional project and subsequent different data model all work perfectly. I can perform different operations using the 2 data layers with seemingly no consequences. Of course the objectsets are different in the 2 data layers as they represent different tables.

My question is this:

Is this approach a good idea? I get most of what is going on behind the scenes but both of these models use System.Data.Objects.ObjectContext. If user A performs an operation using the first data layer while simultaneously user B performs an operation using the second data layer, are there going to be problems with the "shared" objectcontext?

Thanks. And be gentle.

Edit Note: I am using different oc keys

1
If I'm understanding correctly, you're using a new instance per request, right? Since two users can't share one request, they should be using different context instances.StriplingWarrior
Correct. I guess I'm a little spooked because objectcontext has this singularity feeling to it. I just wanted some feedback to reassure myself I am doing this the right way.trevorc

1 Answers

1
votes

You should be OK:

  • The object context is per http request so the context from different users will not interfere with each other
  • Each context updates different tables so they will not interfere with each other

One thing that you may have to watch out for is what happens it two users update the same data at the same time.