diff --git a/src/lib/PnP.Framework/PnPCoreSdk.cs b/src/lib/PnP.Framework/PnPCoreSdk.cs
index 22ac946cf..5675753be 100644
--- a/src/lib/PnP.Framework/PnPCoreSdk.cs
+++ b/src/lib/PnP.Framework/PnPCoreSdk.cs
@@ -42,8 +42,9 @@ private PnPCoreSdk()
/// Get's a PnPContext from a CSOM ClientContext
///
/// CSOM ClientContext
+ /// An existing factory to use for PnPContext creation, instead of an internal one.
/// The equivalent PnPContext
- public async Task GetPnPContextAsync(ClientContext context)
+ public async Task GetPnPContextAsync(ClientContext context, IPnPContextFactory existingFactory = null)
{
Uri ctxUri = new Uri(context.Url);
@@ -61,12 +62,12 @@ public async Task GetPnPContextAsync(ClientContext context)
var iAuthProvider = ctxSettings.AuthenticationManager.PnPCoreAuthenticationProvider;
if (iAuthProvider != null)
{
- var factory0 = BuildContextFactory();
+ var factory0 = existingFactory ?? BuildContextFactory();
return await factory0.CreateAsync(ctxUri, iAuthProvider).ConfigureAwait(false);
}
}
}
- var factory = BuildContextFactory();
+ var factory = existingFactory ?? BuildContextFactory();
return await factory.CreateAsync(ctxUri, AuthenticationProviderFactory.GetAuthenticationProvider(context)).ConfigureAwait(false);
}
@@ -74,10 +75,11 @@ public async Task GetPnPContextAsync(ClientContext context)
/// Get's a PnPContext from a CSOM ClientContext
///
/// CSOM ClientContext
+ /// An existing factory to use for PnPContext creation, instead of an internal one.
/// The equivalent PnPContext
- public PnPContext GetPnPContext(ClientContext context)
+ public PnPContext GetPnPContext(ClientContext context, IPnPContextFactory existingFactory = null)
{
- return GetPnPContextAsync(context).GetAwaiter().GetResult();
+ return GetPnPContextAsync(context, existingFactory).GetAwaiter().GetResult();
}
private IPnPContextFactory BuildContextFactory()