Skip to content

User Service: Remove IBackOfficeUserStore service location from read methods (closes #22404)#22408

Open
AndyButland wants to merge 4 commits intomainfrom
v17/bugfix/22404-remove-back-office-dependency-from-delivery-api-indexing-call-stack
Open

User Service: Remove IBackOfficeUserStore service location from read methods (closes #22404)#22408
AndyButland wants to merge 4 commits intomainfrom
v17/bugfix/22404-remove-back-office-dependency-from-delivery-api-indexing-call-stack

Conversation

@AndyButland
Copy link
Copy Markdown
Contributor

@AndyButland AndyButland commented Apr 10, 2026

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 UserService methods use service location to resolve IBackOfficeUserStore, which is only registered when AddBackOffice() is called.

In delivery-only scenarios (.AddCore().AddDeliveryApi()), this causes a runtime crash when Examine indexing triggers ContentValueSetBuilder.GetValueSets, which calls UserService.GetUsersById to 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 BackOfficeUserStore methods was just a thin wrapper around IUserRepository calls, 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 without IBackOfficeUserStore.

Copilot AI review requested due to automatic review settings April 10, 2026 08:56
Copy link
Copy Markdown
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 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 UserService read methods to use _userRepository inside ICoreScope rather than resolving IBackOfficeUserStore from DI.
  • Added an integration test that boots a core + delivery API app and exercises the affected IUserService read 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.

Comment thread src/Umbraco.Core/Services/UserService.cs
Comment thread tests/Umbraco.Tests.Integration/TestServerTest/CoreConfigurationHttpTests.cs Outdated
- 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>
@AndyButland AndyButland changed the title UserService: Remove IBackOfficeUserStore service location from read methods (closes #22404) User Service: Remove IBackOfficeUserStore service location from read methods (closes #22404) Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants