From 7bcbf082b15c827d12613c2a8fd4a061edec5eb6 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Wed, 19 Jan 2022 14:45:04 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20LocatorFactory?= =?UTF-8?q?=20=E5=8F=82=E6=95=B0=E5=A2=9E=E5=8A=A0=20ServiceProvider=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IPLocator/DefaultIPLocatorProvider.cs | 9 +++++++-- .../Components/IPLocator/IPLocatorOption.cs | 2 +- ...otstrapBlazorServiceCollectionExtensions.cs | 18 ++++++++++++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/BootstrapBlazor/Components/IPLocator/DefaultIPLocatorProvider.cs b/src/BootstrapBlazor/Components/IPLocator/DefaultIPLocatorProvider.cs index 643fc5e32..82f1c972b 100644 --- a/src/BootstrapBlazor/Components/IPLocator/DefaultIPLocatorProvider.cs +++ b/src/BootstrapBlazor/Components/IPLocator/DefaultIPLocatorProvider.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using System; using System.Linq; using System.Net.Http; using System.Threading.Tasks; @@ -17,14 +18,18 @@ internal class DefaultIPLocatorProvider : IIPLocatorProvider { private readonly IPLocatorOption _option; + private readonly IServiceProvider _provider; + /// /// 构造函数 /// + /// /// /// /// - public DefaultIPLocatorProvider(IHttpClientFactory factory, ILogger logger, IOptions option) + public DefaultIPLocatorProvider(IServiceProvider provider, IHttpClientFactory factory, ILogger logger, IOptions option) { + _provider = provider; _option = option.Value; _option.HttpClient = factory.CreateClient(); _option.Logger = logger; @@ -50,7 +55,7 @@ internal class DefaultIPLocatorProvider : IIPLocatorProvider _option.IP = ip; if (_option.LocatorFactory != null) { - var locator = _option.LocatorFactory(); + var locator = _option.LocatorFactory(_provider); if (locator != null) { ret = await locator.Locate(_option); diff --git a/src/BootstrapBlazor/Components/IPLocator/IPLocatorOption.cs b/src/BootstrapBlazor/Components/IPLocator/IPLocatorOption.cs index 3d4d256ee..89f3c8666 100644 --- a/src/BootstrapBlazor/Components/IPLocator/IPLocatorOption.cs +++ b/src/BootstrapBlazor/Components/IPLocator/IPLocatorOption.cs @@ -17,7 +17,7 @@ public class IPLocatorOption /// /// 获得/设置 定位器创建方法未设置使用内部定位器 /// - public Func? LocatorFactory { get; set; } + public Func? LocatorFactory { get; set; } /// /// 获得/设置 IP地址请求超时时间 默认为 3000 毫秒 diff --git a/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs b/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs index fe74bb5fa..682f2894c 100644 --- a/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs +++ b/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs @@ -22,9 +22,8 @@ public static class BootstrapBlazorServiceCollectionExtensions /// /// /// - /// /// - public static IServiceCollection AddBootstrapBlazor(this IServiceCollection services, Action? configureOptions = null, Action? localizationAction = null, Action? locatorAction = null) + public static IServiceCollection AddBootstrapBlazor(this IServiceCollection services, Action? configureOptions = null, Action? localizationAction = null) { services.AddMemoryCache(); services.AddHttpClient(); @@ -67,13 +66,24 @@ public static class BootstrapBlazorServiceCollectionExtensions services.TryAddSingleton(); services.TryAddSingleton, ConfigureOptions>(); + return services; + } + + /// + /// + /// + /// + /// + /// + public static IServiceCollection ConfigIPLocatorOption(this IServiceCollection services, Action locatorAction) + { services.Configure(options => { - locatorAction?.Invoke(options); + locatorAction(options); if (options.LocatorFactory == null) { - options.LocatorFactory = () => new BaiDuIPLocator(); + options.LocatorFactory = provider => new BaiDuIPLocator(); } }); return services; -- Gitee From 287c9e449f872a1cd88838955d0442951ea07a15 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Wed, 19 Jan 2022 14:45:48 +0800 Subject: [PATCH 2/3] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E7=A4=BA=E4=BE=8B?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Shared/Samples/Locator.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor.Shared/Samples/Locator.razor b/src/BootstrapBlazor.Shared/Samples/Locator.razor index 3e0fc388f..4ed241954 100644 --- a/src/BootstrapBlazor.Shared/Samples/Locator.razor +++ b/src/BootstrapBlazor.Shared/Samples/Locator.razor @@ -49,7 +49,7 @@ private IIPLocatorProvider? IPLocator { get; set; } { services.AddBootstrapBlazor(locatorAction: option => { - option.LocatorFactory = () => new CustomerLocator(); + option.LocatorFactory = provider => new CustomerLocator(); }); }
@((MarkupString)Localizer["BasicUsageP12"].Value)
-- Gitee From 385e559a1b31e8206ef9e0185358529707808ad7 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Wed, 19 Jan 2022 14:46:53 +0800 Subject: [PATCH 3/3] chore: bump version 6.2.8 --- src/BootstrapBlazor/BootstrapBlazor.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 8e59b9743..44c06e1c5 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 6.2.8-beta01 + 6.2.8 -- Gitee