Skip to content

Commit 967b5ca

Browse files
authored
doc(IOptions): use IOptions improve performance (#6485)
* refactor: 改用 IOptions<WebsiteOptions> 节约性能 * refactor: 移除 IOptionsMonitor 使用 * doc: 更正单词拼写错误 * refactor: 重构方法
1 parent 981fd03 commit 967b5ca

File tree

107 files changed

+287
-304
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+287
-304
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
@inject IOptionsMonitor<WebsiteOptions> WebsiteOption
1+
@inject IOptions<WebsiteOptions> WebsiteOption
22

3-
<img alt="logo" class="bb-icon" src="@WebsiteOption.CurrentValue.GetAssetUrl("images/logo.png")" />
3+
<img alt="logo" class="bb-icon" src="@WebsiteOption.Value.GetAssetUrl("images/logo.png")" />

src/BootstrapBlazor.Server/Components/Components/BlazorReconnector.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@inject IOptionsMonitor<WebsiteOptions> WebsiteOption
1+
@inject IOptions<WebsiteOptions> WebsiteOption
22

33
<Reconnector>
44
<ReconnectingTemplate>
@@ -59,7 +59,7 @@
5959
</Reconnector>
6060

6161
@code {
62-
private string TemplateUrl => $"{WebsiteOption.CurrentValue.GiteeRepositoryUrl}/wikis/%E9%A1%B9%E7%9B%AE%E6%A8%A1%E6%9D%BF%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B";
62+
private string TemplateUrl => $"{WebsiteOption.Value.GiteeRepositoryUrl}/wikis/%E9%A1%B9%E7%9B%AE%E6%A8%A1%E6%9D%BF%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B";
6363

6464
RenderFragment RenderBootstrapBlazor =>
6565
@<div class="col-12 col-sm-5">
@@ -71,7 +71,7 @@
7171
<p></p>
7272
<div>已提供项目模板方便快速上手 <a class="connection-link" href="@TemplateUrl" target="_blank">项目模板</a></div>
7373
</div>
74-
<img altt="QQ" src="@WebsiteOption.CurrentValue.GetAssetUrl("images/QQGroup@2x.png")" alt="QQGroup" />
74+
<img altt="QQ" src="@WebsiteOption.Value.GetAssetUrl("images/QQGroup@2x.png")" alt="QQGroup" />
7575
<div class="connection-body-tail d-none d-sm-block"></div>
7676
</div>
7777
</div>;

src/BootstrapBlazor.Server/Components/Components/ComponentCard.razor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ namespace BootstrapBlazor.Server.Components.Components;
1313
public sealed partial class ComponentCard
1414
{
1515
[Inject, NotNull]
16-
private IOptionsMonitor<WebsiteOptions>? WebsiteOption { get; set; }
16+
private IOptions<WebsiteOptions>? WebsiteOption { get; set; }
1717

18-
private string ImageUrl => $"{WebsiteOption.CurrentValue.AssetRootPath}images/{Image}";
18+
private string ImageUrl => $"{WebsiteOption.Value.AssetRootPath}images/{Image}";
1919

2020
private string? ClassString => CssBuilder.Default("col-12 col-sm-6 col-md-4 col-lg-3")
2121
.AddClass("d-none", IsHide)

src/BootstrapBlazor.Server/Components/Components/CultureChooser.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<span>@Label</span>
55
<Select Value="@SelectedCulture" OnSelectedItemChanged="@SetCulture">
66
<Options>
7-
@foreach (var kv in BootstrapOptions.CurrentValue.GetSupportedCultures())
7+
@foreach (var kv in BootstrapOptions.Value.GetSupportedCultures())
88
{
99
<SelectOption Text="@GetDisplayName(kv)" Value="@kv.Name" />
1010
}

src/BootstrapBlazor.Server/Components/Components/CultureChooser.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public partial class CultureChooser
1616
{
1717
[Inject]
1818
[NotNull]
19-
private IOptionsMonitor<BootstrapBlazorOptions>? BootstrapOptions { get; set; }
19+
private IOptions<BootstrapBlazorOptions>? BootstrapOptions { get; set; }
2020

2121
[Inject]
2222
[NotNull]

src/BootstrapBlazor.Server/Components/Components/CustomWinBoxContent.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@inject IOptionsMonitor<WebsiteOptions> WebsiteOption
1+
@inject IOptions<WebsiteOptions> WebsiteOption
22

33
<div class="bb-winbox-body">
44
<h3>Custom WinBox Content Create @DateTime.Now</h3>

src/BootstrapBlazor.Server/Components/Components/CustomWinBoxContent.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private async Task SetIconWinBox()
4949
{
5050
if (Option != null)
5151
{
52-
Option.Icon = $"{WebsiteOption.CurrentValue.AssetRootPath}images/Argo-C.png";
52+
Option.Icon = $"{WebsiteOption.Value.AssetRootPath}images/Argo-C.png";
5353
await WinBoxService.SetIcon(Option);
5454
}
5555
}

src/BootstrapBlazor.Server/Components/Components/Header.razor

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
<CultureChooser class="flex-md" />
2525
<ul class="navbar-nav nav-repo ms-3">
2626
<li class="nav-item">
27-
<a class="nav-link p-2" href="@WebsiteOption.CurrentValue.GithubRepositoryUrl" target="_blank">
28-
<img alt="git" src="@WebsiteOption.CurrentValue.GetAssetUrl("images/git.svg")" />
27+
<a class="nav-link p-2" href="@WebsiteOption.Value.GithubRepositoryUrl" target="_blank">
28+
<img alt="git" src="@WebsiteOption.Value.GetAssetUrl("images/git.svg")" />
2929
</a>
3030
</li>
3131
<li class="nav-item">
32-
<a class="nav-link p-2" href="@WebsiteOption.CurrentValue.GiteeRepositoryUrl" target="_blank">
33-
<img alt="gitee" src="@WebsiteOption.CurrentValue.GetAssetUrl("images/gitee.svg")" />
32+
<a class="nav-link p-2" href="@WebsiteOption.Value.GiteeRepositoryUrl" target="_blank">
33+
<img alt="gitee" src="@WebsiteOption.Value.GetAssetUrl("images/gitee.svg")" />
3434
</a>
3535
</li>
3636
<li class="nav-item">

src/BootstrapBlazor.Server/Components/Components/Header.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public partial class Header
1414
{
1515
[Inject]
1616
[NotNull]
17-
private IOptionsMonitor<WebsiteOptions>? WebsiteOption { get; set; }
17+
private IOptions<WebsiteOptions>? WebsiteOption { get; set; }
1818

1919
[Inject]
2020
[NotNull]

src/BootstrapBlazor.Server/Components/Components/InstallContent.razor

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@using Microsoft.Extensions.DependencyInjection
22
@inject PackageVersionService VersionManager
33
@inject IStringLocalizer<InstallContent> Localizer
4-
@inject IOptionsMonitor<WebsiteOptions> WebsiteOption
4+
@inject IOptions<WebsiteOptions> WebsiteOption
55

66
<h3>@Title</h3>
77

@@ -14,17 +14,17 @@
1414
<p class="code-label">1. @Localizer["P11"]</p>
1515
<p class="code-label">2. @Localizer["P12"]</p>
1616
<p class="code-label">3. @Localizer["P13"] <b>Blazor App</b> @Localizer["P14"] <b>@Localizer["P15"]</b>, @Localizer["P16"] <b>Create</b></p>
17-
<img alt="install" src="@WebsiteOption.CurrentValue.GetAssetUrl("images/create-new-application.png")" style="border-radius: 6px;" class="d-none d-sm-block" />
17+
<img alt="install" src="@WebsiteOption.Value.GetAssetUrl("images/create-new-application.png")" style="border-radius: 6px;" class="d-none d-sm-block" />
1818
@ChooseTemplate
1919

2020
<h5>@Localizer["P17"]</h5>
2121
<p class="code-label">1. @Localizer["P18"] <b>nuget.org</b> @Localizer["P19"] <code>BootstrapBlazor</code></p>
2222
<p>@Localizer["P20"] <b>Manage Nuget Packages</b></p>
2323
<Pre @key="@Version" class="no-highlight">dotnet add package BootstrapBlazor --version @Version</Pre>
24-
<img alt="install" src="@WebsiteOption.CurrentValue.GetAssetUrl("images/manage-nuget-packages-for-server-app.png")" style="border-radius: 6px;" class="d-none d-sm-block" />
24+
<img alt="install" src="@WebsiteOption.Value.GetAssetUrl("images/manage-nuget-packages-for-server-app.png")" style="border-radius: 6px;" class="d-none d-sm-block" />
2525

2626
<p class="code-label">2. @Localizer["P21"]</p>
27-
<img alt="install" src="@WebsiteOption.CurrentValue.GetAssetUrl("images/nuget_install.png")" style="width: 1000px; border-radius: 6px;" class="d-none d-sm-block" />
27+
<img alt="install" src="@WebsiteOption.Value.GetAssetUrl("images/nuget_install.png")" style="width: 1000px; border-radius: 6px;" class="d-none d-sm-block" />
2828

2929
<p class="code-label">3. @Localizer["P22"]</p>
3030
<p>@Localizer["P23"]</p>
@@ -69,4 +69,4 @@
6969
<p class="code-label">1. @Localizer["P39"] <code>Button</code> @Localizer["P40"]</p>
7070
<Pre>&lt;Button Color="Color.Primary" Icon="fa-solid fa-font-awesome" Text="@Localizer["P41"]" /&gt;</Pre>
7171
<p class="code-label">2. @Localizer["P42"] <b>Visual studio</b> @Localizer["P43"] <kbd>F5</kbd> @Localizer["P44"]</p>
72-
<img alt="install" src="@WebsiteOption.CurrentValue.GetAssetUrl("images/preview.png")" style="border-radius: 6px;" class="d-none d-sm-block" />
72+
<img alt="install" src="@WebsiteOption.Value.GetAssetUrl("images/preview.png")" style="border-radius: 6px;" class="d-none d-sm-block" />

0 commit comments

Comments
 (0)