This is a migrated thread and some comments may be shown as answers.

Handling context in Web and Multi-Threaded apps

1 Answer 124 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rafael
Top achievements
Rank 1
Rafael asked on 25 Apr 2011, 09:06 PM
Hello,

I’m trying to use OpenAccess for a website. Classic architecture , Webforms, UI, Business, DAL layers.. Using the Domain Model generated by OA, no 2nd level cache.

The first problem I had was when adding items to a basket (Table Basket --> BasketLineItems, 1-N .. classic)

Initially I had on my DataAccessLayerBase.cs:

private static HighLevelFOModel _dbHighLevelFOContext;
        
        public static HighLevelFOModel GetHighLevelFODBContext()
        {
            if (_dbHighLevelFOContext == null)
                return _dbHighLevelFOContext = new HighLevelFOModel();
            return _dbHighLevelFOContext;
        }

Of course, I ended with several dbContexts and baskets containing different items as I was adding/removing them, all messed-up.
Then I used the HttpModule solution. (Masterpage wasn’t pretty because I have a DAL)
Now this one seems better BUT I don’t know why, under IIS Integrated Mode it doesn’t work, I get another messed-up basket on each request and errors like:

Error: “Object references between two different object scopes are not allowed. The object 'HighLevelFO.Entities.Basket' is already managed by 'ObjectScopeImpl 0x3ed6c25 Telerik.OpenAccess.RT.EnlistableObjectScope' and was tried to be managed again by 'ObjectScopeImpl 0x2f8458d Telerik.OpenAccess.RT.EnlistableObjectScope'.”

If I switch to IIS Classic mode it *seems* ok.

Note: for reading purposes only, it’s not a problem as for example I read the products catalog and I put it on memory cache.

I was trying to avoid getting down to the good old 100% pure ADO.net to handle all the CRUD related with basket/user account.
But the truth is that I’m not feeling confident with OpenAccess dealing with these critical objects.

•    What will happen if using IIS Webfarms > 1?
•    What will happen with 2+ load-balanced IIS Servers?
•    Why this solution doesn’t work with IIS Integrated mode?
•    What to use in the HTTPModule? HttpContext.Current.Items or  HttpContext.Current.Session?

I think it would be really useful to have an example for this kind of real-life-real medium/heavy loaded websites scenarios.

Regards,

Rafael

1 Answer, 1 is accepted

Sort by
0
Zoran
Telerik team
answered on 28 Apr 2011, 06:17 PM
Hello Rafael,

 This problem means that you have an object that is probably obtained from the database by one context/scope instance and you are trying to update it with another one, maybe you are caching the item or keeping it between requests in the Session state. When you create a context/scope on per-request basis which is the very recommended way, you should not keep any object alive between requests. If you need to do that, like with a shopping basket, you should work with proxy objects and then translate them to OpenAccess persistent objects, at the moment you decide to write to the database. 
I recommend you to have a look into this sample project that should present my idea to you in code.

As for the scope/context management, I believe that the best approach is to use the HttpContext.Items collection and I will point you to another article where the usage of it is presented without a HttpModule. This approach has been proven in real production environments if that is a concern for you. Our own web site which is heavily loaded (www.telerik.com) is an example of that!

Kind regards,
Zoran
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Rafael
Top achievements
Rank 1
Answers by
Zoran
Telerik team
Share this question
or