Skip to content

Commit aa72a54

Browse files
committed
refactor: 改用 TryAdd 注入
1 parent 5e009f9 commit aa72a54

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/components/BootstrapBlazor.IP2Region/Extensions/ServiceCollectionExtensions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

55
using BootstrapBlazor.Components;
6+
using Microsoft.Extensions.DependencyInjection.Extensions;
67

78
namespace Microsoft.Extensions.DependencyInjection;
89

@@ -12,14 +13,14 @@ namespace Microsoft.Extensions.DependencyInjection;
1213
public static class BootstrapBlazoIP2RegionExtensions
1314
{
1415
/// <summary>
15-
/// 添加 AzureOpenAIService 服务
16+
/// 添加 IP2RegionService 服务
1617
/// </summary>
1718
/// <param name="services"></param>
18-
public static IServiceCollection AddBootstrapBlazorIP2RegionfService(this IServiceCollection services)
19+
public static IServiceCollection AddBootstrapBlazorIP2RegionService(this IServiceCollection services)
1920
{
20-
services.AddSingleton<IIpLocatorProvider, IP2RegionService>();
21+
services.TryAddSingleton<IIpLocatorProvider, IP2RegionService>();
2122
#if NET8_0_OR_GREATER
22-
services.AddKeyedSingleton<IIpLocatorProvider, IP2RegionService>("BootstrapBlazor.IP2Region");
23+
services.TryAddKeyedSingleton<IIpLocatorProvider, IP2RegionService>("BootstrapBlazor.IP2Region");
2324
#endif
2425

2526
services.AddOptionsMonitor<IP2RegionOptions>();

0 commit comments

Comments
 (0)