I am trying to create a library(class library) for sharepoint which will have all sharepoint dll to interact with sharepoint server to upload files,documents and create document library and document set.
Now this library could be consumed by clients like web application(asp.net webform or mvc) or console application or web api/wcf services or windows form anything.
So here I am bit confused with creating repository patterna and unit of work layer in order to manage client context object.
I am not sure whether to allow creation of client context for each operation or whether to create client context once and reuse or whether to create clientcontext each time.
I have search alot but was unable to find any reference or article to create repository layer like the way it is created in case of Entity framework DbContext
.
I am using Client-Side Object Model(CSOM library) and my library is all about content management system to manage files and meta data.
I will appreciate any help :)
Update : Sample code to upload file on sharepoint domain
ClientContext context = new ClientContext("http://SiteUrl"); // Starting with ClientContext, the constructor requires a URL to the server running SharePoint.
context.Credentials = new SharePointOnlineCredentials(username, password);
// The SharePoint web at the URL.
Web myWeb = context.Web;
List myLibrary = myWeb.Lists.GetByTitle("MyProject"); //This is called document library so in sharepoint document Library is the root where we can create
//Document Set(Advance version of folder) or folder(Simple Folder) or upload files directly inside document library
FileCreationInformation info = new FileCreationInformation();
info.Url = "Sample.txt";
info.Overwrite = true;
info.Content = System.IO.File.ReadAllBytes("C://sample.txt"); //This will be user uploaded file that will be dynamic
myLibrary.RootFolder.Files.Add(info);
context.ExecuteQuery(); // Execute the query to the server.This is like EF SaveChanges method
Some References : https://learn.microsoft.com/en-us/previous-versions/msp-n-p/ff649690(v=pandp.10)