IObjectScope Best Practices for SharePoint WebParts

Thread is closed for posting
2 posts, 0 answers
  1. Michael
    Michael avatar
    1 posts
    Member since:
    Mar 2009

    Posted 29 Apr 2009 Link to this post


    I've had a look at your best practices example from your code library here. The first approach is to use the master page as the creation point for the IObjectScope instance. This method isn't viable for SharePoint. I'm just wondering what your guidance for SharePoint web parts is?

    For example if I have multiple web parts on the one page all calling my services layer which is exposed to web part via a singleton pattern, will the following call in this services layer be thread safe and will it handle all the queries / transactions etc to the database properly:


    Or should I be doing something else in my services layer, like making sure that each service call makes use of the ObjectScopeProvider1.GetNewObjectScope()  ?

    What is Telerik's guidance around this type of scenario?
  2. Zoran
    Zoran avatar
    534 posts

    Posted 08 May 2009 Link to this post

    Hello Daniel P,

    My suggestion is to use a helper class that should control the initialization of the object scope and it's disposal. It should be called by all the web parts that should pass their Page as parameter and that way they will use the same IObjectScope instance. That way the application should be thread safe and OpenAccess will handle all the concurrency issues.

    Here is a sample implementation of such class:
    public class ScopeController 
        public static IObjectScope GetScope(Page page) 
            if ((IObjectScope)page.Session["SCOPE"] == null
                IObjectScope scope = Database.Get("SharePointConnection").GetObjectScope(); 
                page.Session["SCOPE"] = scope; 
                page.Unload += new EventHandler(page_Unload); 
            return (IObjectScope)page.Session["SCOPE"]; 
        static void page_Unload(object sender, EventArgs e) 
            Page page = (Page)sender; 
            IObjectScope scope = (IObjectScope)page.Session["SCOPE"]; 

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top