Fix scoped ASP.NET health checks, correct AddHealthContributor docs#1636
Merged
Conversation
a193273 to
1924924
Compare
Contributor
Summary - All Code Coverage (ubuntu-latest)
|
…thContributor documentation
1924924 to
6038063
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue with scoped ASP.NET health checks by ensuring that a service scope is created for each health check execution, matching ASP.NET's HealthCheckService behavior. It also corrects documentation that incorrectly stated health contributors were registered as scoped services when they are actually singletons.
Key changes:
- Modified
HealthAggregatorto create a service scope for each Microsoft health check execution, enabling support for scoped dependencies - Corrected XML documentation comments in
EndpointServiceCollectionExtensionsto accurately reflect that health contributors are registered as singleton services - Enhanced test infrastructure to validate service scopes and added a comprehensive test for scoped health checks using Entity Framework Core
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Management/test/Endpoint.Test/Steeltoe.Management.Endpoint.Test.csproj | Added Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore package dependency to support testing scoped health checks |
| src/Management/test/Endpoint.Test/Actuators/Health/HealthAggregationTest.cs | Added new test method and TestDbContext class to verify scoped ASP.NET health checks work correctly |
| src/Management/src/Endpoint/Actuators/Health/EndpointServiceCollectionExtensions.cs | Fixed documentation comments to correctly state that health contributors are registered as singleton services |
| src/Common/test/TestResources/TestWebApplicationBuilderFactory.cs | Added service provider configuration for the Host to enable scope validation in tests |
| src/Common/test/TestResources/TestHostBuilderFactory.cs | Added service provider configuration for web host builder to enable scope validation in tests |
| src/Common/src/Common/HealthChecks/HealthAggregator.cs | Implemented scope creation for each Microsoft health check to support scoped services like EF Core DbContext |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…gationTest.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
TimHess
approved these changes
Jan 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
Fixes #1635.
Quality checklist
If your change affects other repositories, such as Documentation, Samples and/or MainSite, add linked PRs here.