From 2662fb05c27163c8d14adf903b1f66a0e0027e10 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 19 Oct 2025 14:55:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=B3=A8=E5=85=A5?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/ServiceCollectionExtensions.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 binding/csharp/IP2Region.Net/Extensions/ServiceCollectionExtensions.cs diff --git a/binding/csharp/IP2Region.Net/Extensions/ServiceCollectionExtensions.cs b/binding/csharp/IP2Region.Net/Extensions/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..eeacdb3 --- /dev/null +++ b/binding/csharp/IP2Region.Net/Extensions/ServiceCollectionExtensions.cs @@ -0,0 +1,27 @@ +using IP2Region.Net.Abstractions; +using IP2Region.Net.XDB; + +namespace Microsoft.Extensions.DependencyInjection; + +/// +/// BootstrapBlazor 服务扩展类 +/// +public static class BootstrapBlazoIP2RegionExtensions +{ + /// + /// 添加 IP2RegionService 服务 + /// + /// + public static IServiceCollection AddIP2RegionService(this IServiceCollection services, string path, CachePolicy cachePolicy = CachePolicy.Content) + { + services.AddSingleton( provider => + { + return new Searcher(cachePolicy, path); + }); +#if NET8_0_OR_GREATER + services.AddKeyedSingleton("IP2Region.Net"); +#endif + + return services; + } +}