-
-
Notifications
You must be signed in to change notification settings - Fork 375
chore(Hosting): remove Microsoft.Extensions.Hosting.Abstractions deps #7492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRemoves 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 BootstrapBlazorErrorBoundarysequenceDiagram
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
Class diagram for updated error handling and removed hosting abstractionsclassDiagram
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
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this 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) | ||
| { |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
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.
| { | |
| { | |
| await handler.HandlerExceptionAsync(exception); |
| // 非开发模式下弹窗提示错误信息 | ||
| await ToastService.Error(ToastTitle, exception.Message); | ||
| } | ||
| // 非开发模式下弹窗提示错误信息 |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
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).
| // 非开发模式下弹窗提示错误信息 | |
| // 弹窗提示错误信息 |
Link issues
fixes #7491
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Remove reliance on Microsoft.Extensions.Hosting abstractions from BootstrapBlazor hosting and error handling.
Enhancements:
Tests: