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

IObjectScope Best Practices for SharePoint WebParts

1 Answer 123 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.
Michael
Top achievements
Rank 1
Michael asked on 29 Apr 2009, 05:31 AM

Hello,

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:

ObjectScopeProvider1.ObjectScope(); 

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?

1 Answer, 1 is accepted

Sort by
0
Zoran
Telerik team
answered on 08 May 2009, 12:42 PM
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"]; 
        scope.Dispose(); 
        page.Session.Remove("SCOPE"); 
    }   


Greetings,
Zoran
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.
Tags
General Discussions
Asked by
Michael
Top achievements
Rank 1
Answers by
Zoran
Telerik team
Share this question
or