zhaolei
2020-11-20 921de2254ff5712a44ed8575ee8efe34252f6603
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Net.Http;
 
namespace Bootstrap.Security
{
    /// <summary>
    /// BootstrapAdmin 管理系统接口服务操作类
    /// </summary>
    public static class BootstrapAdminInterfaceServiceCollectionExtensions
    {
        /// <summary>
        /// 添加 BootstrapAdmin 接口服务
        /// </summary>
        /// <param name="services">服务容器集合</param>
        /// <param name="configure">HttpClient 配置回调方法</param>
        /// <returns>IServiceCollection 服务容器集合</returns>
        public static IServiceCollection AddBootstrapAdminInterfaceService(this IServiceCollection services, Action<HttpClient>? configure = null)
        {
            services.AddHttpClient<BootstrapAdminHttpClient>((provider, client) =>
            {
                var authHost = provider.GetRequiredService<IConfiguration>()["BootstrapAdminAuthenticationOptions:AuthHost"] ?? "";
                client.BaseAddress = new Uri($"{authHost}/api/Interface/");
                configure?.Invoke(client);
            });
            services.AddBootstrapAdminInterface();
            return services;
        }
    }
}