Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Jan 10, 2026

Link issues

fixes #7491

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Remove reliance on Microsoft.Extensions.Hosting abstractions from BootstrapBlazor hosting and error handling.

Enhancements:

  • Stop injecting and using IHostEnvironment in the error boundary and always surface errors via toast notifications when a handler is present.
  • Remove custom host environment abstractions and related service registrations from the BootstrapBlazor DI extensions.

Tests:

  • Delete unit tests that covered the removed host environment extension helpers.

Copilot AI review requested due to automatic review settings January 10, 2026 12:42
@bb-auto bb-auto bot added the chore This are tasks or bot action label Jan 10, 2026
@bb-auto bb-auto bot added this to the v10.2.0 milestone Jan 10, 2026
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 10, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Removes the dependency on Microsoft.Extensions.Hosting.Abstractions by eliminating IHostEnvironment usage, its related registration, and helper types/tests, and simplifies error handling behavior accordingly.

Sequence diagram for new exception rendering behavior in BootstrapBlazorErrorBoundary

sequenceDiagram
    participant Caller
    participant ErrorBoundary as BootstrapBlazorErrorBoundary
    participant Handler as IHandlerException
    participant Toast as IToastService

    Caller->>ErrorBoundary: RenderException(exception, handler)
    alt handler is not null
        ErrorBoundary->>Toast: Error(ToastTitle, exception.Message)
        Toast-->>ErrorBoundary: Task completed
        ErrorBoundary-->>Caller: return
    else handler is null
        ErrorBoundary-->>Caller: return without action
    end
Loading

Class diagram for updated error handling and removed hosting abstractions

classDiagram
    direction LR

    class BootstrapBlazorErrorBoundary {
        - NavigationManager NavigationManager
        - IStringLocalizer Localizer
        - IConfiguration Configuration
        - IToastService ToastService
        - ILogger Logger
        + Func~Exception, string, Task~? UserErrorHandler
        + Task RenderException(Exception exception, IHandlerException handler)
    }

    class IHandlerException {
        <<interface>>
        + Task HandlerExceptionAsync(Exception exception, string content)
    }

    class MockWasmHostEnvironment {
        <<removed>>
    }

    class HostEnvironmentExtensions {
        <<removed>>
    }

    class IHostEnvironment {
        <<from_Microsoft_Extensions_Hosting_Abstractions>>
    }

    BootstrapBlazorErrorBoundary .. IHandlerException : uses

    MockWasmHostEnvironment ..|> IHostEnvironment : removed
    HostEnvironmentExtensions .. IHostEnvironment : removed extensions

    class BootstrapBlazorServiceCollectionExtensions {
        + IServiceCollection AddBootstrapBlazor(IServiceCollection services, IConfiguration configuration, Action~BootstrapBlazorOptions~ configureOptions)
    }

    BootstrapBlazorServiceCollectionExtensions .. IHostEnvironment : removed registration
    BootstrapBlazorServiceCollectionExtensions .. MockWasmHostEnvironment : removed registration
Loading

File-Level Changes

Change Details Files
Stop using IHostEnvironment in the Blazor error boundary and simplify handler behavior.
  • Remove HostEnvironment dependency injection property from the error boundary component.
  • Delete development-mode conditional around exception handling so the handler always shows a toast error message when present.
  • Adjust using directives to drop Microsoft.Extensions.Hosting.
src/BootstrapBlazor/Components/ErrorLogger/BootstrapBlazorErrorBoundary.cs
Remove custom IHostEnvironment provisioning and associated hosting abstractions usage from the service collection extensions.
  • Remove registration of MockWasmHostEnvironment as IHostEnvironment from the BootstrapBlazor service registration.
  • Drop the Microsoft.Extensions.Hosting using from the extensions file.
src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs
Delete now-unused hosting environment helpers, mock implementation, and their unit tests.
  • Remove HostEnvironmentExtensions helper type.
  • Remove MockWasmHostEnvironment implementation.
  • Remove HostEnvironmentExtensions unit tests.
src/BootstrapBlazor/Extensions/HostEnvironmentExtensions.cs
src/BootstrapBlazor/Services/MockWasmHostEnvironment.cs
test/UnitTest/Extensions/HostEnvironmentExtensionsTest.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#7491 Remove all code-level dependencies on Microsoft.Extensions.Hosting (e.g., IHostEnvironment usage and related usings) from the BootstrapBlazor project.
#7491 Remove supporting infrastructure (registrations, helper classes, and tests) that existed solely to provide or work with Microsoft.Extensions.Hosting abstractions, ensuring the package is no longer required.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ArgoZhang ArgoZhang merged commit 043b80d into main Jan 10, 2026
4 of 6 checks passed
@ArgoZhang ArgoZhang deleted the feat-host branch January 10, 2026 12:42
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Removing IHostEnvironment from BootstrapBlazorErrorBoundary changes behavior so that handler exceptions are always surfaced as toast errors; if the dev-mode behavior (calling HandlerExceptionAsync to show detailed info) is still desired, consider using an alternative environment check (e.g., via configuration) instead of dropping the distinction entirely.
  • With MockWasmHostEnvironment and HostEnvironmentExtensions removed, review any remaining code paths or samples that might have relied on the mocked environment behavior for WASM to ensure they now either use a different mechanism or no longer assume IHostEnvironment is available.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Removing IHostEnvironment from BootstrapBlazorErrorBoundary changes behavior so that handler exceptions are always surfaced as toast errors; if the dev-mode behavior (calling HandlerExceptionAsync to show detailed info) is still desired, consider using an alternative environment check (e.g., via configuration) instead of dropping the distinction entirely.
- With MockWasmHostEnvironment and HostEnvironmentExtensions removed, review any remaining code paths or samples that might have relied on the mocked environment behavior for WASM to ensure they now either use a different mechanism or no longer assume IHostEnvironment is available.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the dependency on Microsoft.Extensions.Hosting.Abstractions package from the BootstrapBlazor project. The change eliminates IHostEnvironment usage and related mock implementations that were previously used to detect WebAssembly and Development/Production environments.

Changes:

  • Removed Microsoft.Extensions.Hosting.Abstractions package references from all target frameworks in Directory.Build.props
  • Deleted HostEnvironmentExtensions, MockWasmHostEnvironment, and related test files
  • Removed IHostEnvironment service registration from BootstrapBlazor service collection extensions
  • Modified error handling logic in BootstrapBlazorErrorBoundary to no longer differentiate between Development and Production environments

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/BootstrapBlazor/Directory.Build.props Removed Microsoft.Extensions.Hosting.Abstractions package references for all .NET versions
src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs Removed IHostEnvironment service registration and related import
src/BootstrapBlazor/Extensions/HostEnvironmentExtensions.cs Deleted extension method for IHostEnvironment.IsWasm()
src/BootstrapBlazor/Services/MockWasmHostEnvironment.cs Deleted mock implementation of IHostEnvironment
src/BootstrapBlazor/Components/ErrorLogger/BootstrapBlazorErrorBoundary.cs Removed IHostEnvironment injection and environment-based conditional error handling
test/UnitTest/Extensions/HostEnvironmentExtensionsTest.cs Deleted unit tests for the removed extension method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

await OnErrorAsync(exception);

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.
// 非开发模式下弹窗提示错误信息
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore This are tasks or bot action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(Hosting): remove Microsoft.Extensions.Hosting.Abstractions deps

2 participants