Skip to content

Commit 80ef545

Browse files
authored
fix(ErrorLogger): throw exception on wasm mode (#6210)
* fix: 修复 Wasm 下无法使用 Host 问题 * chore: bump version 9.7.3 * refactor: 注入 MockHostEnvironment 实现类 * Revert "fix: 修复 Wasm 下无法使用 Host 问题" This reverts commit a54d3d4. * feat: 增加调试环境支持 * refactor: 增加排除标签
1 parent d5cd54c commit 80ef545

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
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.7.2</Version>
4+
<Version>9.7.3</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using Microsoft.Extensions.Configuration;
77
using Microsoft.Extensions.DependencyInjection.Extensions;
8+
using Microsoft.Extensions.Hosting;
89
using System.Globalization;
910

1011
namespace Microsoft.Extensions.DependencyInjection;
@@ -36,6 +37,9 @@ public static IServiceCollection AddBootstrapBlazor(this IServiceCollection serv
3637
services.TryAddSingleton<IZipArchiveService, DefaultZipArchiveService>();
3738
services.TryAddSingleton(typeof(IDispatchService<>), typeof(DefaultDispatchService<>));
3839

40+
// 增加 IHostEnvironment 服务
41+
services.TryAddSingleton<IHostEnvironment, MockWasmHostEnvironment>();
42+
3943
// 增加 OtpOptions 配置支持
4044
services.AddOptionsMonitor<OtpOptions>();
4145

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
using Microsoft.Extensions.FileProviders;
7+
using Microsoft.Extensions.Hosting;
8+
9+
namespace BootstrapBlazor.Components;
10+
11+
[ExcludeFromCodeCoverage]
12+
class MockWasmHostEnvironment : IHostEnvironment
13+
{
14+
#if DEBUG
15+
public string EnvironmentName { get; set; } = "Development";
16+
#else
17+
public string EnvironmentName { get; set; } = "Production";
18+
#endif
19+
20+
public string ApplicationName { get; set; } = "BootstrapBlazor";
21+
22+
public string ContentRootPath { get; set; } = "";
23+
24+
public IFileProvider ContentRootFileProvider { get; set; } = null!;
25+
}

0 commit comments

Comments
 (0)