Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing to create PnPContext from ClientContext with existing IPnPContextFactory #762

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/lib/PnP.Framework/PnPCoreSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ private PnPCoreSdk()
/// Get's a PnPContext from a CSOM ClientContext
/// </summary>
/// <param name="context">CSOM ClientContext</param>
/// <param name="existingFactory">An existing factory to use for PnPContext creation, instead of an internal one.</param>
/// <returns>The equivalent PnPContext</returns>
public async Task<PnPContext> GetPnPContextAsync(ClientContext context)
public async Task<PnPContext> GetPnPContextAsync(ClientContext context, IPnPContextFactory existingFactory = null)
{
Uri ctxUri = new Uri(context.Url);

Expand All @@ -61,23 +62,24 @@ public async Task<PnPContext> 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);
}

/// <summary>
/// Get's a PnPContext from a CSOM ClientContext
/// </summary>
/// <param name="context">CSOM ClientContext</param>
/// <param name="existingFactory">An existing factory to use for PnPContext creation, instead of an internal one.</param>
/// <returns>The equivalent PnPContext</returns>
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()
Expand Down