From 372269e32faec43e374e3d0b12b7748d3a6ff14a Mon Sep 17 00:00:00 2001 From: "2248356998 qq.com" <2248356998@qq.com> Date: Thu, 23 Oct 2025 21:33:19 +0800 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20GetUniqueName=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/AssemblyExtensions.cs | 4 +--- src/BootstrapBlazor/Services/CacheManager.cs | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/BootstrapBlazor/Extensions/AssemblyExtensions.cs b/src/BootstrapBlazor/Extensions/AssemblyExtensions.cs index d5b31f26ab3..6f6557a1b86 100644 --- a/src/BootstrapBlazor/Extensions/AssemblyExtensions.cs +++ b/src/BootstrapBlazor/Extensions/AssemblyExtensions.cs @@ -14,7 +14,5 @@ static class AssemblyExtensions /// /// /// - public static string GetUniqueName(this Assembly assembly) => assembly.IsCollectible - ? $"{assembly.GetName().Name}-{assembly.GetHashCode()}" - : $"{assembly.GetName().Name}"; + public static string GetUniqueName(this Assembly assembly) => CacheManager.GetUniqueName(assembly); } diff --git a/src/BootstrapBlazor/Services/CacheManager.cs b/src/BootstrapBlazor/Services/CacheManager.cs index 90eca88ad94..ae1e060d28a 100644 --- a/src/BootstrapBlazor/Services/CacheManager.cs +++ b/src/BootstrapBlazor/Services/CacheManager.cs @@ -216,6 +216,26 @@ private List GetAllValues(MemoryCache cache) } #endif + #region Assembly + /// + /// 获得唯一类型名称方法 + /// + /// + /// + public static string GetUniqueName(Assembly assembly) + { + //key不拼接,作为当前静态实例唯一标识,因为GetUniqueName方法会被频繁调用 + return Instance.GetOrCreate(assembly, _ => + { + return assembly.IsCollectible + ? $"{assembly.GetName().Name}-{assembly.GetHashCode()}" + : $"{assembly.GetName().Name}"; + } + ); + } + + #endregion + #region Count public static int ElementCount(object? value) { From 2677e9289b8b1f7373031b70c9462d06243ed96b Mon Sep 17 00:00:00 2001 From: "2248356998 qq.com" <2248356998@qq.com> Date: Thu, 23 Oct 2025 22:01:23 +0800 Subject: [PATCH 2/9] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=89=B9?= =?UTF-8?q?=E6=80=A7=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BootstrapModuleComponentBase.cs | 10 +++------- src/BootstrapBlazor/Services/CacheManager.cs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs b/src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs index 5b1ba65b30a..fce8b6c11a3 100644 --- a/src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs +++ b/src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs @@ -3,8 +3,6 @@ // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone -using System.Reflection; - namespace BootstrapBlazor.Components; /// @@ -82,13 +80,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender) protected virtual void OnLoadJSModule() { var type = this.GetType(); - var inherited = type.GetCustomAttribute() == null; - if (inherited) + if (CacheManager.GetAttribute(type) == null) { - var attributes = type.GetCustomAttributes(); - if (attributes.Any()) + var attr = CacheManager.GetAttribute(type); + if (attr != null) { - var attr = attributes.First(); AutoInvokeDispose = attr.AutoInvokeDispose; AutoInvokeInit = attr.AutoInvokeInit; diff --git a/src/BootstrapBlazor/Services/CacheManager.cs b/src/BootstrapBlazor/Services/CacheManager.cs index ae1e060d28a..be393dce654 100644 --- a/src/BootstrapBlazor/Services/CacheManager.cs +++ b/src/BootstrapBlazor/Services/CacheManager.cs @@ -216,6 +216,22 @@ private List GetAllValues(MemoryCache cache) } #endif + #region Attribute + /// + /// 获得类型特性标签方法 + /// + /// + /// + public static Attr? GetAttribute(Type type) where Attr : Attribute + { + return Instance.GetOrCreate((type, typeof(Attr)), _ => + { + return type.GetCustomAttribute(); + }); + } + + #endregion + #region Assembly /// /// 获得唯一类型名称方法 From 25570d90d808eeb25604a551eadb1293e5b1ae32 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 24 Oct 2025 08:26:41 +0800 Subject: [PATCH 3/9] chore: bump version 9.11.5-beta04 --- src/BootstrapBlazor/BootstrapBlazor.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 78c373a09a7..67b04463a54 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,11 +1,11 @@  - 9.11.5-beta03 + 9.11.5-beta04 - 10.0.0-rc.2.1.2 + 10.0.0-rc.2.1.3 From ef6acb08f2ecc5d8cc0f8f6bdeab5f385b2b75dc Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 24 Oct 2025 08:40:36 +0800 Subject: [PATCH 4/9] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Services/CacheManager.cs | 3 +-- .../Components/BootstrapModuleComponentBaseTest.cs | 11 +++++------ test/UnitTest/Extensions/AssemblyExtensionsTest.cs | 7 +++++++ test/UnitTest/Services/ConnectionHubTest.cs | 7 +++++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/BootstrapBlazor/Services/CacheManager.cs b/src/BootstrapBlazor/Services/CacheManager.cs index be393dce654..f565886d273 100644 --- a/src/BootstrapBlazor/Services/CacheManager.cs +++ b/src/BootstrapBlazor/Services/CacheManager.cs @@ -246,8 +246,7 @@ public static string GetUniqueName(Assembly assembly) return assembly.IsCollectible ? $"{assembly.GetName().Name}-{assembly.GetHashCode()}" : $"{assembly.GetName().Name}"; - } - ); + }); } #endregion diff --git a/test/UnitTest/Components/BootstrapModuleComponentBaseTest.cs b/test/UnitTest/Components/BootstrapModuleComponentBaseTest.cs index c7227618a59..7babbaf2a2c 100644 --- a/test/UnitTest/Components/BootstrapModuleComponentBaseTest.cs +++ b/test/UnitTest/Components/BootstrapModuleComponentBaseTest.cs @@ -18,10 +18,10 @@ public void InvokeVoidAsync_Ok() } [Fact] - public void InvokeAsync_Ok() + public async Task InvokeAsync_Ok() { var cut = Context.RenderComponent(); - cut.InvokeAsync(() => cut.Instance.InvokeAsyncTest()); + await cut.InvokeAsync(() => cut.Instance.InvokeAsyncTest()); Assert.True(cut.Instance.InvokeRunner); } @@ -42,18 +42,17 @@ public async Task InvokeVoidAsyncTest() } } - [JSModuleAutoLoader("mock.js", JSObjectReference = true, AutoInvokeDispose = true, AutoInvokeInit = true)] class MockObjectReferenceComponent : Select { public bool InvokeRunner { get; set; } public async Task InvokeAsyncTest() { - await base.InvokeAsync(Id); - await base.InvokeAsync(Id, TimeSpan.FromMinutes(1)); + await InvokeAsync(Id); + await InvokeAsync(Id, TimeSpan.FromMinutes(1)); using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(1000); - await base.InvokeAsync(Id, cancellationTokenSource.Token); + await InvokeAsync(Id, cancellationTokenSource.Token); InvokeRunner = true; } diff --git a/test/UnitTest/Extensions/AssemblyExtensionsTest.cs b/test/UnitTest/Extensions/AssemblyExtensionsTest.cs index 0dcc43b177b..c3227dfd30c 100644 --- a/test/UnitTest/Extensions/AssemblyExtensionsTest.cs +++ b/test/UnitTest/Extensions/AssemblyExtensionsTest.cs @@ -13,6 +13,13 @@ public class AssemblyExtensionsTest [Fact] public void GetUniqueName_Ok() { + var sc = new ServiceCollection(); + sc.AddBootstrapBlazor(); + + var provider = sc.BuildServiceProvider(); + var cacheManager = provider.GetRequiredService(); + cacheManager.GetStartTime(); + var type = Type.GetType("BootstrapBlazor.Components.AssemblyExtensions, BootstrapBlazor"); Assert.NotNull(type); diff --git a/test/UnitTest/Services/ConnectionHubTest.cs b/test/UnitTest/Services/ConnectionHubTest.cs index 243d2aec2e3..c70447488ec 100644 --- a/test/UnitTest/Services/ConnectionHubTest.cs +++ b/test/UnitTest/Services/ConnectionHubTest.cs @@ -13,6 +13,13 @@ public class ConnectionHubTest [Fact] public async Task Callback_Ok() { + var sc = new ServiceCollection(); + sc.AddBootstrapBlazor(); + + var provider = sc.BuildServiceProvider(); + var cacheManager = provider.GetRequiredService(); + cacheManager.GetStartTime(); + var context = new TestContext(); context.JSInterop.Mode = JSRuntimeMode.Loose; context.Services.AddBootstrapBlazor(); From 18bc4596a7c1672f3869ca8c03812aa6de983d4e Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 24 Oct 2025 08:56:59 +0800 Subject: [PATCH 5/9] =?UTF-8?q?revert:=20=E6=92=A4=E9=94=80=E6=9B=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/BootstrapModuleComponentBaseTest.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/UnitTest/Components/BootstrapModuleComponentBaseTest.cs b/test/UnitTest/Components/BootstrapModuleComponentBaseTest.cs index 7babbaf2a2c..c96a42c5cbe 100644 --- a/test/UnitTest/Components/BootstrapModuleComponentBaseTest.cs +++ b/test/UnitTest/Components/BootstrapModuleComponentBaseTest.cs @@ -42,17 +42,19 @@ public async Task InvokeVoidAsyncTest() } } + [JSModuleAutoLoader("mock.js", JSObjectReference = true, AutoInvokeDispose = true, AutoInvokeInit = true)] class MockObjectReferenceComponent : Select { public bool InvokeRunner { get; set; } public async Task InvokeAsyncTest() { - await InvokeAsync(Id); - await InvokeAsync(Id, TimeSpan.FromMinutes(1)); + // base 关键字不能省略 + await base.InvokeAsync(Id); + await base.InvokeAsync(Id, TimeSpan.FromMinutes(1)); using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(1000); - await InvokeAsync(Id, cancellationTokenSource.Token); + await base.InvokeAsync(Id, cancellationTokenSource.Token); InvokeRunner = true; } From 2a6f3798235a4cef5aad77ad8e69b84f44701324 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 24 Oct 2025 09:06:33 +0800 Subject: [PATCH 6/9] =?UTF-8?q?refactor:=20=E6=92=A4=E9=94=80=20GetAttribu?= =?UTF-8?q?te=20=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BootstrapModuleComponentBase.cs | 8 +++++--- src/BootstrapBlazor/Services/CacheManager.cs | 16 ---------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs b/src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs index fce8b6c11a3..56c1d62c4ed 100644 --- a/src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs +++ b/src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs @@ -80,11 +80,13 @@ protected override async Task OnAfterRenderAsync(bool firstRender) protected virtual void OnLoadJSModule() { var type = this.GetType(); - if (CacheManager.GetAttribute(type) == null) + var inherited = type.GetCustomAttribute() == null; + if (inherited) { - var attr = CacheManager.GetAttribute(type); - if (attr != null) + var attributes = type.GetCustomAttributes(); + if (attributes.Any()) { + var attr = attributes.First(); AutoInvokeDispose = attr.AutoInvokeDispose; AutoInvokeInit = attr.AutoInvokeInit; diff --git a/src/BootstrapBlazor/Services/CacheManager.cs b/src/BootstrapBlazor/Services/CacheManager.cs index f565886d273..93a3d44ce62 100644 --- a/src/BootstrapBlazor/Services/CacheManager.cs +++ b/src/BootstrapBlazor/Services/CacheManager.cs @@ -216,22 +216,6 @@ private List GetAllValues(MemoryCache cache) } #endif - #region Attribute - /// - /// 获得类型特性标签方法 - /// - /// - /// - public static Attr? GetAttribute(Type type) where Attr : Attribute - { - return Instance.GetOrCreate((type, typeof(Attr)), _ => - { - return type.GetCustomAttribute(); - }); - } - - #endregion - #region Assembly /// /// 获得唯一类型名称方法 From ce948adb156f727b15b29a4f8c3883fa46735144 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 24 Oct 2025 09:07:49 +0800 Subject: [PATCH 7/9] =?UTF-8?q?revert:=20=E6=92=A4=E9=94=80=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E7=A9=BA=E9=97=B4=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/BaseComponents/BootstrapModuleComponentBase.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs b/src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs index 56c1d62c4ed..5b1ba65b30a 100644 --- a/src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs +++ b/src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs @@ -3,6 +3,8 @@ // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone +using System.Reflection; + namespace BootstrapBlazor.Components; /// From e57bf9b24e7dc054b5bf7fd05195e4ea34e5516d Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 24 Oct 2025 09:10:36 +0800 Subject: [PATCH 8/9] =?UTF-8?q?revert:=20=E6=92=A4=E9=94=80=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Services/ConnectionHubTest.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/UnitTest/Services/ConnectionHubTest.cs b/test/UnitTest/Services/ConnectionHubTest.cs index c70447488ec..243d2aec2e3 100644 --- a/test/UnitTest/Services/ConnectionHubTest.cs +++ b/test/UnitTest/Services/ConnectionHubTest.cs @@ -13,13 +13,6 @@ public class ConnectionHubTest [Fact] public async Task Callback_Ok() { - var sc = new ServiceCollection(); - sc.AddBootstrapBlazor(); - - var provider = sc.BuildServiceProvider(); - var cacheManager = provider.GetRequiredService(); - cacheManager.GetStartTime(); - var context = new TestContext(); context.JSInterop.Mode = JSRuntimeMode.Loose; context.Services.AddBootstrapBlazor(); From 7ba89fd66f74e31d45de2a6978a647a1e6831d35 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 24 Oct 2025 09:12:12 +0800 Subject: [PATCH 9/9] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/BootstrapModuleComponentBaseTest.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/UnitTest/Components/BootstrapModuleComponentBaseTest.cs b/test/UnitTest/Components/BootstrapModuleComponentBaseTest.cs index c96a42c5cbe..f7e96156818 100644 --- a/test/UnitTest/Components/BootstrapModuleComponentBaseTest.cs +++ b/test/UnitTest/Components/BootstrapModuleComponentBaseTest.cs @@ -32,11 +32,11 @@ class MockComponent : BootstrapModuleComponentBase public async Task InvokeVoidAsyncTest() { - await base.InvokeVoidAsync(Id); - await base.InvokeVoidAsync(Id, TimeSpan.FromMinutes(1)); + await InvokeVoidAsync(Id); + await InvokeVoidAsync(Id, TimeSpan.FromMinutes(1)); using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(1000); - await base.InvokeVoidAsync(Id, cancellationTokenSource.Token); + await InvokeVoidAsync(Id, cancellationTokenSource.Token); InvokeVoidRunner = true; } @@ -49,12 +49,11 @@ class MockObjectReferenceComponent : Select public async Task InvokeAsyncTest() { - // base 关键字不能省略 - await base.InvokeAsync(Id); - await base.InvokeAsync(Id, TimeSpan.FromMinutes(1)); + await InvokeAsync(Id); + await InvokeAsync(Id, TimeSpan.FromMinutes(1)); using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(1000); - await base.InvokeAsync(Id, cancellationTokenSource.Token); + await InvokeAsync(Id, cancellationTokenSource.Token); InvokeRunner = true; }