In SharePoint 2013 CSOM is it better to pass a Context object around, or a Url to open a context?
Which would be the best example: (Please consider there may be a lot of methods preforming tasks)
1) Pass Context, open Web
EnableSomethingOnWeb(ClientContext ctx, bool enable){
ctx.Load(ctx.Web);
// enable something
ctx.ExecuteQuery();
}
var ctx = new ClientContext("http://myweb");
EnableSomethingOnWeb(ctx, true);
2) Pass Url, open ClientContext, Open web
EnableSomethingOnWeb(string Url, bool enable){
var ctx = new ClientContext(Url);
ctx.Load(ctx.Web);
// enable something
ctx.ExecuteQuery();
}
EnableSomethingOnWeb(webUrl, true);
3) Pass Web, Execute ClientContext
EnableSomethingOnWeb(Web web, bool enable){
// enable something
web.Context.ExecuteQuery();
}
var ctx = new ClientContext("http://myweb");
ctx.Load(ctx.Web);
EnableSomethingOnWeb(ctx.Web, true);
*keep in mind following calls may continue pass this web object around.