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

PerRequest Context

1 Answer 72 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.
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
sitefinitysteve asked on 09 Jul 2010, 07:45 PM
The IObjectScope had the GetPerRequestScope Method, whats the equivalent in a domain context method?

1 Answer, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 13 Jul 2010, 08:45 PM
Hello Steve,

You could use the following approach as an equivalent of the GetPerRequestScope scenario:
public class ContextFactory
    {
        public static DataContext GetContextPerRequest()
        {
            HttpContext httpContext = HttpContext.Current;
            if (httpContext == null)
            {
                return new DataContext();
            }
            else
            {
                String key = httpContext.GetHashCode().ToString("x") + Thread.CurrentContext.ContextID.ToString();
                DataContext context = null;
                if (httpContext == null)
                {
                    context = new DataContext();
                }
                else
                {
                    context = (DataContext)httpContext.Items[key];
                    if (context == null)
                    {
                        context = new DataContext();
                        httpContext.Items[key] = context;
                    }
                }
                return context;
            }
        }
    }

You may find the following code library example useful as well:
 "Implementing Context factory for Telerik OpenAccess ORM"
Hope that helps.

Best wishes,
Damyan Bogoev
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
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Answers by
Damyan Bogoev
Telerik team
Share this question
or