Sharepoint ClientContext usage in services

Viewed 507

I use the SharePoint SDK in one of our WCF services.

To get a byte array (document) from SharePoint I use the ClientContext class of the SDK. The calls to SharePoint are all wrapped in a custom class called SharePointConnector(like a sort of repository pattern).

My goal is to inject the SharePointConnector class in my wcf service by using an interface ISharePointConnector.

My questions:

  1. Should I create the ClientContext in the constructor of SharePointConnector or should use it per call, wrapped in a using block ? Concerns that I have: is it an expensive call to create the ClientContext ? Thread safe when multiple calls are made on the same instance of clientContext member variable?
  2. At what point should I register the url so that it can be used in the constructor of ClientContext ?

Note that by implementing it by creating the ClientContext instance in the constructor, there is a difficulty to get the url that is required to create an instance of the ClientContext because the constructor injection by the DI container....

1 Answers
Related