User Service: Remove IBackOfficeUserStore service location from read methods (closes #22404)#22408
Open
AndyButland wants to merge 4 commits intomainfrom
Conversation
…ce configured setups.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes service-location of IBackOfficeUserStore from UserService read methods so they work in delivery-only configurations (without AddBackOffice()), preventing runtime crashes during indexing paths that resolve creator/writer user names.
Changes:
- Refactored several
UserServiceread methods to use_userRepositoryinsideICoreScoperather than resolvingIBackOfficeUserStorefrom DI. - Added an integration test that boots a core + delivery API app and exercises the affected
IUserServiceread methods.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Umbraco.Core/Services/UserService.cs | Replaces IBackOfficeUserStore service-location in read paths with repository-backed queries/scopes. |
| tests/Umbraco.Tests.Integration/TestServerTest/CoreConfigurationHttpTests.cs | Adds a regression test ensuring IUserService read methods don’t throw in delivery-only boot. |
- Add IRuntimeState to UserService and mirror the DbException catch from BackOfficeUserStore.GetAsync(int) in GetUserById, so the upgrade-time fallback to GetForUpgrade is preserved. - Use non-empty arguments in the delivery-only integration test so the repository-backed code paths are actually exercised, not just the early-return guards. - Update UserServiceCrudTests to pass IRuntimeState to the new constructor parameter. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
IBackOfficeUserStore service location from read methods (closes #22404)
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
The issue #22404 reports a problem with Umbraco configured only for delivery API setup in a load balanced environment (supported from 17.3 after #21630).
Currently various
UserServicemethods use service location to resolveIBackOfficeUserStore, which is only registered whenAddBackOffice()is called.In delivery-only scenarios (
.AddCore().AddDeliveryApi()), this causes a runtime crash when Examine indexing triggersContentValueSetBuilder.GetValueSets, which callsUserService.GetUsersByIdto look up content creator/writer names.It seems a little bit of a smell that we have this service location, but I assume it was done to avoid repeated code between this service and the user store. I haven't removed it completely to avoid making an unnecessarily large change, but have done so for the affected method and other "read" ones (
GetUsersById,GetUserById,GetAsync,GetAllInGroup).As each of these
BackOfficeUserStoremethods was just a thin wrapper aroundIUserRepositorycalls, we don't lose much by replacing the service location with direct repository access.Testing
Automated
Existing integration tests for the amended user service methods continue to pass.
I've added a new integration test (
CoreConfigurationHttpTests.CoreWithDeliveryApi_UserServiceReadMethodsDoNotThrow) that boots a delivery-only app and calls all five fixed methods, verifying they work withoutIBackOfficeUserStore.