How can we set the spfxContext when we use pnpjs in a service layer.
In service classes we normally use serviceScope to get all the required dependencies. Through serviceScope.consume(PageContext.serviceKey) we can only get reference to this.context.pageContext, where as spfxContext requires this.context to be passed. Is it possible to get this.context via serviceScope.consume ? If not, are there any other ways to set the spfxContext.
PS: We are trying to use library components for services classes and CDN for loading PnPJs.
Please specify what version of the library you are using: [1.3.3]
Please specify what version(s) of SharePoint you are targeting: [Sharepoint Online]
Can you share a repo we can clone showing what you are trying to do?
I will get a repo ready in some time...
@patrick-rodgers
Sorry I forgot raising the question.
Here is a sample
https://github.com/kmprasad4u/SPFx-Library-Service-Sample
@patrick-rodgers
Any suggestions ?
Hi @kmprasad4u - sorry for delay, been a busy period for me. Thank you for the example - yes your workaround is perfectly valid and I think is probably the easiest way to move forward. If you look at the source we do what you are doing (read the url) but your use the baseUrl overrides that and uses the value you specify. At the end of the day the same thing is happening.
I wasn't aware you could only get the page context in this scenario so this is something we should put in the getting started docs. Thanks!
Thanks for the clarification :)
Most helpful comment
Hi @kmprasad4u - sorry for delay, been a busy period for me. Thank you for the example - yes your workaround is perfectly valid and I think is probably the easiest way to move forward. If you look at the source we do what you are doing (read the url) but your use the baseUrl overrides that and uses the value you specify. At the end of the day the same thing is happening.
I wasn't aware you could only get the page context in this scenario so this is something we should put in the getting started docs. Thanks!