Builder Extensions: Make AddWebComponents() idempotent (closes #22344)#22347
Merged
Builder Extensions: Make AddWebComponents() idempotent (closes #22344)#22347
AddWebComponents() idempotent (closes #22344)#22347Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes IUmbracoBuilder.AddWebComponents() safe to call multiple times by adding an idempotency guard consistent with the existing AddCore() pattern, preventing duplicate DI registrations (notably duplicate health checks) when AddWebComponents() is invoked explicitly after higher-level builder calls.
Changes:
- Added a marker-based idempotency guard to
AddWebComponents()to ensure it runs only once per service collection. - Added an integration regression test covering the exact call chain that previously caused duplicate
"umbraco-ready"health check registration failures.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs |
Adds a marker singleton + early-return guard to make AddWebComponents() idempotent and avoid duplicate registrations. |
tests/Umbraco.Tests.Integration/TestServerTest/CoreConfigurationTests.cs |
Adds AddWebComponents_IsIdempotent regression test to ensure HealthCheckService resolves without duplicate-name exceptions after the problematic builder chain. |
AddWebComponents() idempotent (closes #22344)
AndyButland
added a commit
that referenced
this pull request
Apr 7, 2026
…) (#22347) Ensure AddWebComponents is idempotent.
This was referenced Apr 10, 2026
Merged
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
#22344 raises a concern that from 17.3, after we'd introduced support for running Umbraco with different components of backoffice, website and Delivery API in #21630, that the
AddWebComponents()wasn't made idempotent.This PR adds an idempotency guard to
AddWebComponents()using the same marker-class pattern already used byAddCore(), preventing duplicate health check registration whenAddWebComponents()is called explicitly afterAddBackOffice().Testing
Automated
A regression integration test has been added that reproduces the exact scenario from the issue and asserts
HealthCheckServicecan be resolved without duplicate name errors.Manual
See steps to reproduce on the linked issue. Before the fix an exception would be thrown. Now the application will start normally.