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

Scope in Seesion?

2 Answers 78 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.
Thomas Kaske
Top achievements
Rank 1
Thomas Kaske asked on 07 Jan 2010, 12:55 PM
Hello everybody,

i have a question about the scope in web applications. I read the best practices and it says that it is ok to put the scope in the session and clear the session after that. So that means, taht i create the scope on every request.

So we have about 60 classes which are mapped in our company and it takes around 2,5 seconds to create a scope every time, but when we create the scope on the first time and never ever:-) again and then put it into the session and keep it there it saves time to. We just look on a request in the session and take it out of there.

What is the best way. Your examples are alwys on some classes with some members but how I mentioned we have around 60 classes with lots of members. I understand that it takes time for the OR Mapper to check the mapping but that must go faster.

What would you suggest me to put it into the session or create it everytime or maybe i did understand something wrong???

2 Answers, 1 is accepted

Sort by
0
IT-Als
Top achievements
Rank 1
answered on 08 Jan 2010, 07:52 AM
Hi Thomas,

If it takes 2,5 seconds to create something is really wrong.

In webapps you generally follow the pattern of "one thread (request) - one scope"... However, on creation of the very first scope it takes longer because mapping configuration has to be read and so on.
If you take a look at the provided (with OA) ObjectScopeProvider (I don't know if you create scopes from that one)..but anyway... Take a look at it.

It has a Database.Get method call which return a Database instance according to your connection info in the config. That's where the mapping configuration and so on is read, but no scope is created yet..

The scope is created when you do a GetObjectScope() on the retrieved database instance (the one you got from the Database.Get method call)... and this should perform very well...

Take a look at your code that handles the scope, maybe you're creating the Database instance over and over...  You only need to create the Database instance once...and then create scopes from this instance.

The number of classes is not relevant on scope creation (it might be on Database.Get method call, but you only do this once)

Regards

Henrik
0
Zoran
Telerik team
answered on 08 Jan 2010, 09:33 AM
Hello Thomas,

It is possible to store the scope in session, but I would recommend you to create it, as Henrik suggested on a per-request basis. Scope creation is a very cheap operation and I also assume that the call that takes 2,5 seconds is actually the creation of the database object. Storing the scope in session is not even possible in large web applications where the Session is stored in SQL Server database as it is not a Serializable object.
You may be already aware of it but I would still point you to the approach that has proven to be most successful and popular with our customers, namely, to store the scope in the HttpContext.Items collection and keep it there for the lifecycle of a web request.

Best wishes,
Zoran
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
Thomas Kaske
Top achievements
Rank 1
Answers by
IT-Als
Top achievements
Rank 1
Zoran
Telerik team
Share this question
or