refactor: 增加 Keyed 逻辑

This commit is contained in:
Argo Zhang 2025-10-19 15:08:16 +08:00
parent ddb2b4ff1d
commit 24dcb24e24
1 changed files with 5 additions and 2 deletions

View File

@ -14,12 +14,15 @@ public static class BootstrapBlazoIP2RegionExtensions
/// <param name="services"></param> /// <param name="services"></param>
public static IServiceCollection AddIP2RegionService(this IServiceCollection services, string path, CachePolicy cachePolicy = CachePolicy.Content) public static IServiceCollection AddIP2RegionService(this IServiceCollection services, string path, CachePolicy cachePolicy = CachePolicy.Content)
{ {
services.AddSingleton<ISearcher>( provider => services.AddSingleton<ISearcher>(provider =>
{ {
return new Searcher(cachePolicy, path); return new Searcher(cachePolicy, path);
}); });
#if NET8_0_OR_GREATER #if NET8_0_OR_GREATER
services.AddKeyedSingleton<ISearcher, Searcher>("IP2Region.Net"); services.AddKeyedSingleton<ISearcher>("IP2Region.Net", (provider, _) =>
{
return new Searcher(cachePolicy, path);
});
#endif #endif
return services; return services;