mirror of
https://github.com/lionsoul2014/ip2region.git
synced 2025-12-08 19:25:22 +00:00
28 lines
775 B
C#
28 lines
775 B
C#
using IP2Region.Net.Abstractions;
|
|
using IP2Region.Net.XDB;
|
|
|
|
namespace Microsoft.Extensions.DependencyInjection;
|
|
|
|
/// <summary>
|
|
/// BootstrapBlazor 服务扩展类
|
|
/// </summary>
|
|
public static class BootstrapBlazoIP2RegionExtensions
|
|
{
|
|
/// <summary>
|
|
/// 添加 IP2RegionService 服务
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
public static IServiceCollection AddIP2RegionService(this IServiceCollection services, string path, CachePolicy cachePolicy = CachePolicy.Content)
|
|
{
|
|
services.AddSingleton<ISearcher>( provider =>
|
|
{
|
|
return new Searcher(cachePolicy, path);
|
|
});
|
|
#if NET8_0_OR_GREATER
|
|
services.AddKeyedSingleton<ISearcher, Searcher>("IP2Region.Net");
|
|
#endif
|
|
|
|
return services;
|
|
}
|
|
}
|