Skip to content

Commit 8c86ed9

Browse files
authored
refactor(BootstrapBlazorRoot): support nested usage (#5552)
* refactor: 兼容 Root 多层嵌套 * test: 更新单元测试 * doc: 更新注释 * chore: bump version 9.4.7
1 parent d7e68cd commit 8c86ed9

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.4.7-beta04</Version>
4+
<Version>9.4.7</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Services/BootstrapBlazorRootRegisterService.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class BootstrapBlazorRootRegisterService
1414
private readonly Dictionary<object, List<BootstrapBlazorRootContent>> _providersByIdentifier = [];
1515

1616
/// <summary>
17-
/// add provider
17+
/// Add provider
1818
/// </summary>
1919
/// <param name="identifier"></param>
2020
/// <param name="provider"></param>
@@ -30,7 +30,7 @@ public void AddProvider(object identifier, BootstrapBlazorRootContent provider)
3030
}
3131

3232
/// <summary>
33-
/// remove provider
33+
/// Remove provider
3434
/// </summary>
3535
/// <param name="identifier"></param>
3636
/// <param name="provider"></param>
@@ -58,7 +58,7 @@ public void RemoveProvider(object identifier, BootstrapBlazorRootContent provide
5858
}
5959

6060
/// <summary>
61-
/// get all providers by identifier
61+
/// Get all providers by identifier
6262
/// </summary>
6363
/// <param name="identifier"></param>
6464
/// <returns></returns>
@@ -69,30 +69,27 @@ public List<BootstrapBlazorRootContent> GetProviders(object identifier)
6969
}
7070

7171
/// <summary>
72-
/// subscribe
72+
/// Subscribe
7373
/// </summary>
7474
/// <param name="identifier"></param>
7575
/// <param name="subscriber"></param>
7676
public void Subscribe(object identifier, BootstrapBlazorRootOutlet subscriber)
7777
{
7878
if (_subscribersByIdentifier.ContainsKey(identifier))
7979
{
80-
throw new InvalidOperationException($"There is already a subscriber to the content with the given root ID '{identifier}'.");
80+
return;
8181
}
8282

8383
_subscribersByIdentifier.Add(identifier, subscriber);
8484
}
8585

8686
/// <summary>
87-
/// 取消订阅
87+
/// Unsubscribe
8888
/// </summary>
8989
/// <param name="identifier"></param>
9090
public void Unsubscribe(object identifier)
9191
{
92-
if (!_subscribersByIdentifier.Remove(identifier))
93-
{
94-
throw new InvalidOperationException($"The subscriber with the given root ID '{identifier}' is already unsubscribed.");
95-
}
92+
_subscribersByIdentifier.Remove(identifier);
9693
}
9794

9895
/// <summary>

test/UnitTest/Services/BootstrapBlazorRootRegisterServiceTest.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ public void Subscribe_Ok()
2828
var service = new BootstrapBlazorRootRegisterService();
2929
var identifier = new object();
3030
service.Subscribe(identifier, new BootstrapBlazorRootOutlet());
31-
var exception = Assert.ThrowsAny<InvalidOperationException>(() => service.Subscribe(identifier, new BootstrapBlazorRootOutlet()));
32-
Assert.Equal("There is already a subscriber to the content with the given root ID 'System.Object'.", exception.Message);
33-
34-
exception = Assert.ThrowsAny<InvalidOperationException>(() => service.Unsubscribe(new object()));
35-
Assert.Equal("The subscriber with the given root ID 'System.Object' is already unsubscribed.", exception.Message);
31+
service.Unsubscribe(new object());
3632
}
3733

3834
[Fact]

0 commit comments

Comments
 (0)