forked from FarmMaps/FarmMapsApiClient
29 lines
1.1 KiB
C#
29 lines
1.1 KiB
C#
|
using System.Net.Http;
|
||
|
using FarmmapsApi.HttpMessageHandlers;
|
||
|
using FarmmapsApi.Models;
|
||
|
using FarmmapsApi.Services;
|
||
|
using IdentityModel.Client;
|
||
|
using Microsoft.Extensions.DependencyInjection;
|
||
|
|
||
|
namespace FarmmapsApi
|
||
|
{
|
||
|
public static class Extensions
|
||
|
{
|
||
|
public static IServiceCollection AddFarmmapsServices(this IServiceCollection serviceCollection, Configuration configuration)
|
||
|
{
|
||
|
return serviceCollection
|
||
|
.AddSingleton(configuration)
|
||
|
.AddSingleton<IDiscoveryCache>(sp =>
|
||
|
{
|
||
|
var httpFactory = sp.GetRequiredService<IHttpClientFactory>();
|
||
|
return new DiscoveryCache(configuration.DiscoveryEndpointUrl,
|
||
|
() => httpFactory.CreateClient());
|
||
|
})
|
||
|
.AddTransient<OpenIdConnectService>()
|
||
|
.AddTransient<FarmmapsAuthenticationHandler>()
|
||
|
.AddHttpClient<FarmmapsApiService>()
|
||
|
.AddHttpMessageHandler<FarmmapsAuthenticationHandler>()
|
||
|
.Services;;
|
||
|
}
|
||
|
}
|
||
|
}
|