Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Reflection;

Expand All @@ -32,10 +31,6 @@ class BootstrapBlazorErrorBoundary : ErrorBoundaryBase
[NotNull]
private NavigationManager? NavigationManager { get; set; }

[Inject]
[NotNull]
private IHostEnvironment? HostEnvironment { get; set; }

/// <summary>
/// 获得/设置 自定义错误处理回调方法
/// </summary>
Expand Down Expand Up @@ -161,16 +156,8 @@ public async Task RenderException(Exception exception, IHandlerException? handle

if (handler != null)
{
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change removes important error handling behavior. Previously, when a handler was provided and the application was in Development mode, the code would call handler.HandlerExceptionAsync() to render detailed error content in the UI. This functionality is now completely removed, meaning components implementing IHandlerException (like Layout and ModalDialog) will no longer be able to display detailed error information through their custom error handlers. Instead, only a simple toast message is shown regardless of the environment. This appears to be an unintended breaking change that could significantly impact debugging and error handling in development environments. Consider preserving the ability to call handler.HandlerExceptionAsync() without depending on IHostEnvironment, perhaps by always calling it or adding a configuration option.

Suggested change
{
{
await handler.HandlerExceptionAsync(exception);

Copilot uses AI. Check for mistakes.
if (HostEnvironment.IsDevelopment())
{
// IHandlerException 处理异常逻辑
await handler.HandlerExceptionAsync(exception, ExceptionContent);
}
else
{
// 非开发模式下弹窗提示错误信息
await ToastService.Error(ToastTitle, exception.Message);
}
// 非开发模式下弹窗提示错误信息
Copy link

Copilot AI Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "非开发模式下弹窗提示错误信息" (Display error information in a toast in non-development mode), but this is now misleading. The code previously had conditional logic based on the environment (Development vs Production), but after removing the IHostEnvironment dependency, this now always shows a toast error regardless of the environment. The comment should be updated to reflect that this behavior now applies in all environments, or simply say "弹窗提示错误信息" (Display error information in a toast).

Suggested change
// 非开发模式下弹窗提示错误信息
// 弹窗提示错误信息

Copilot uses AI. Check for mistakes.
await ToastService.Error(ToastTitle, exception.Message);
return;
}

Expand Down
5 changes: 0 additions & 5 deletions src/BootstrapBlazor/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(NET8Version)" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="$(NET6Version)" />
<PackageReference Include="Microsoft.Extensions.Http" Version="$(NET8Version)" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="$(NET8Version)" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(NET8Version)" />
</ItemGroup>

Expand All @@ -47,7 +46,6 @@
<PackageReference Include="Microsoft.Extensions.Localization" Version="$(NET7Version)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(NET8Version)" />
<PackageReference Include="Microsoft.Extensions.Http" Version="$(NET8Version)" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="$(NET8Version)" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(NET8Version)" />
</ItemGroup>

Expand All @@ -57,7 +55,6 @@
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="$(NET10Version)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(NET10Version)" />
<PackageReference Include="Microsoft.Extensions.Http" Version="$(NET10Version)" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="$(NET10Version)" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="$(NET8Version)" />
</ItemGroup>

Expand All @@ -67,7 +64,6 @@
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="$(NET10Version)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(NET10Version)" />
<PackageReference Include="Microsoft.Extensions.Http" Version="$(NET10Version)" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="$(NET10Version)" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="$(NET9Version)" />
</ItemGroup>

Expand All @@ -77,7 +73,6 @@
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="$(NET10Version)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(NET10Version)" />
<PackageReference Include="Microsoft.Extensions.Http" Version="$(NET10Version)" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="$(NET10Version)" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="$(NET10Version)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using System.Globalization;

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

// 增加 IHostEnvironment 服务
services.TryAddSingleton<IHostEnvironment, MockWasmHostEnvironment>();

// 增加 OtpOptions 配置支持
services.AddOptionsMonitor<OtpOptions>();

Expand Down
21 changes: 0 additions & 21 deletions src/BootstrapBlazor/Extensions/HostEnvironmentExtensions.cs

This file was deleted.

25 changes: 0 additions & 25 deletions src/BootstrapBlazor/Services/MockWasmHostEnvironment.cs

This file was deleted.

30 changes: 0 additions & 30 deletions test/UnitTest/Extensions/HostEnvironmentExtensionsTest.cs

This file was deleted.

Loading