PerRequest Context

Thread is closed for posting
2 posts, 0 answers
  1. Steve
    Steve avatar
    1888 posts
    Member since:
    Dec 2008

    Posted 09 Jul 2010 Link to this post

    The IObjectScope had the GetPerRequestScope Method, whats the equivalent in a domain context method?

  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 13 Jul 2010 Link to this post

    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
Back to Top