Help with setting up dependency injection #1560
-
Here's my code sample, from what I understood at this documentation // from StartUp.cs
....
services.AddPnPCore(options =>
{
options.PnPContext.GraphFirst = true;
options.PnPContext.GraphCanUseBeta = false;
options.PnPContext.GraphAlwaysUseBeta = false;
options.HttpRequests.UserAgent = "MyApiProject";
options.Sites.Add("MySite", new PnPCoreSiteOptions()
{
SiteUrl = sharepointSiteUrl
});
});
services.AddPnPCoreAuthentication(options =>
{
options.Credentials.Configurations.Add("CertConfigName", new PnPCoreAuthenticationCredentialConfigurationOptions()
{
ClientId = sharepointClientId,
TenantId = sharepointTenantId,
X509Certificate = new PnPCoreAuthenticationX509CertificateOptions()
{
StoreName = StoreName.My,
StoreLocation = StoreLocation.CurrentUser,
Thumbprint = sharepointThumbprint
}
});
options.Credentials.DefaultConfiguration = "CertConfigName";
options.Sites.Add("MySite", new PnPCoreAuthenticationSiteOptions()
{
AuthenticationProviderName = "CertConfigName"
});
}); // using in classes via dependency injection
public class MyClass(IPnPContextFactory pnpFactory)
{
...
} However, I get the exception: Additional information: I am using Autofac to populate my dependencies |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
At the end of SDK Basics / Getting started / Configuring the needed services there is an alternative setup that I used in my test application and it works fine with Dependency Injection. See below, I removed some code that set options and such but the options.DefaultAuthenticationProvider property is the interesting part:
In the application I just added the IPnPContextFactory as a parameter in the default constructor:
|
Beta Was this translation helpful? Give feedback.
At the end of SDK Basics / Getting started / Configuring the needed services there is an alternative setup that I used in my test application and it works fine with Dependency Injection. See below, I removed some code that set options and such but the options.DefaultAuthenticationProvider property is the interesting part: