zhaolei
9 days ago 4a2e5b9a21940f11757be37d99f0944e240e908b
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
32
33
34
35
36
using Prow.Web;
using System;
 
namespace Microsoft.Extensions.DependencyInjection
{
    /// <summary>
    /// IP地理位置扩展操作类
    /// </summary>
    public static class IPLocatorServicesCollectionExtensions
    {
        /// <summary>
        /// IP地理位置定位器配置回调委托
        /// </summary>
        private static Action<IPLocatorOption>? _configure;
 
        /// <summary>
        /// 添加IP定位服务
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configure">定位器配置选项</param>
        /// <returns></returns>
        public static IServiceCollection AddIPLocator(this IServiceCollection services, Action<IPLocatorOption>? configure = null)
        {
            _configure = configure;
            services.AddHttpClient();
            services.AddSingleton<IIPLocatorProvider, DefaultIPLocatorProvider>();
            return services;
        }
 
        /// <summary>
        /// IPLocatorOption 配置回调方法
        /// </summary>
        /// <returns></returns>
        internal static void ConfigureOption(IPLocatorOption option) => _configure?.Invoke(option);
    }
}