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:
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....
I would very much recommend you to use the ClientContext
within the scope of the Methods (or whatever calls are in your case) and not instanciating it in the constructor, mainly for two reasons:
ClientContext
to your needs in a given situation. Resources: As you already pointed out, the ClientContext
implements the IDisposable
interface and should therefore be disposed/released after using it, this will save you some resources. You know the drill:
using (ClientContext clientCtx = new ClientContext(siteUrl)){ //do your stuff... }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.