This designed API is a result from a Visual Studio SharePoint Add-In Template Project refactoring, to be useful at Hight Trust (SharePoint 2016 Hosted) or Low Trust (SharePoint OnLine) or Hybrid Farm scenarios; this is can a alternative if do you want a decople solution for C# Provider Hosted Solutions. This was tested in SharePoint 2016 and SharePoint Online project customizations using Asp.NET Web Forms.
i. Needed to install a nuget package for Microsoft.Identity.Model and Newtonsoft.Json;
or
ii. Microsoft SharePoint Components SDK for SharePoint Online and SharePoint 2016;
-The second way is better!
Instantiate ClientContext object from this API object called SharePointContextCSOM and all the magic is will be succed! Because this Api has all specified sharepoint artefact items that the application needs to contextualize, giving to developer only responsability to make C.R.U.D. roles, view the example:
//For current site:
SharePointContextCSOM _providerHostedApi = new SharePointContextCSOM(HttpContext.Current, "NameOfList");
//For remote site:
SharePointContextCSOM _providerHostedApi =
new SharePointContextCSOM(HttpContext.Current, "http://remote/site/access", "NameOfList");
using(ClientContext ctx = _providerHostedApi.SharePointClientCtx)
{
//To do SharePoint consume business rule...
}