📚 Docs - This is the way that I've have setup the Servic...
Raz Cohen
This was auto-generated by a Slack integration.
Message text - This is the way that I've have setup the ServiceCollection with a Permit instance in my Program.cs file:
``
services.AddSingleton<Permit>(sp => new Permit(configuration["AppSettings:PermitApiKey"], pdp: configuration["AppSettings:permitPdpUrl"], raiseErrors: true));
``You can then inject an instance of a
Permit
class into your controllers and use it directly. Additionally, if you find that a specific API endpoint is not implemented in the Permit .NET SDK, you can add a Permit specific HttpClient like so:```services.AddHttpClient("permit-cloud", options =>
{
options.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("bearer", configuration["AppSettings:PermitApiKey"]);
options.BaseAddress = new Uri("https://api.permit.io/v2/facts/");
});```
You can then create a Permit cloud specific
HttpClient
by using a HttpClientFactory
like so:``
var permitCloudHttpClient = httpClientFactory.CreateClient("permit-cloud");
``Similarly, if you want to invoke an endpoint on the PDP API, you can setup an
HttpClient
like so:```services.AddHttpClient("permit-pdp", options =>
{
options.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("bearer", configuration["AppSettings:PermitApiKey"]);
options.BaseAddress = new Uri(configuration["AppSettings:permitPdpUrl"]);
});```
Where the
permitPdpUrl
configuration setting defaults to http://localhost:7766
. You can use this client in the same way you use the Permit cloud client example above:``
var pdpHttpClient = httpClientFactory.CreateClient("permit-pdp");
``User - mruwe