Skip to content

Register no-op implementation of IMemberPartialViewCacheInvalidator in headless setups#19666

Merged
Migaroez merged 2 commits intov13/devfrom
v13/bugfix/ensure-implementation-of-IMemberPartialViewCacheInvalidator-is-registered
Jul 8, 2025
Merged

Register no-op implementation of IMemberPartialViewCacheInvalidator in headless setups#19666
Migaroez merged 2 commits intov13/devfrom
v13/bugfix/ensure-implementation-of-IMemberPartialViewCacheInvalidator-is-registered

Conversation

@AndyButland
Copy link
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

Resolves: #19661

Description

As the linked issue discusses, when we don't have a call to .AddWebsite() in Program.cs, the IMemberPartialViewCacheInvalidator has no registered implementation, which causes an error when logging in.

This PR registers a no-op implementation of this interface that'll be overridden by the primary implementation if .AddWebsite() is used.

Testing

Setup Program.cs like the following, so there's no front-end website but you should be able log into the backoffice.

Verify that you can't before this PR is applied but you can after.

Revert to the standard setup for Umbraco with the front-end rendering, put a breaking point in MemberPartialViewCacheInvalidator.ClearPartialViewCacheItems and verify that the primary implementation is called when saving a member in the backoffice.

@AndyButland AndyButland requested review from Migaroez and Copilot and removed request for Copilot July 4, 2025 05:03
Copy link
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 ensures that a default no-op implementation of IMemberPartialViewCacheInvalidator is registered in headless (no-website) setups to prevent missing-service errors while allowing the real implementation to override it when .AddWebsite() is used.

  • Registers NoopMemberPartialViewCacheInvalidator in UmbracoBuilder.AddCoreServices()
  • Adds a new internal no-op class under Cache.PartialViewCacheInvalidators
  • Removes a duplicate using directive

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs Registers default no-op invalidator for headless setups
src/Umbraco.Core/Cache/PartialViewCacheInvalidators/NoopMemberPartialViewCacheInvalidator.cs Introduces an internal no-op implementation of the cache invalidator
Comments suppressed due to low confidence (2)

src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs:349

  • Consider adding a unit or integration test to verify that in a headless setup (without .AddWebsite()), the DI container resolves IMemberPartialViewCacheInvalidator to the no-op implementation and does not throw when logging in.
            Services.AddUnique<IMemberPartialViewCacheInvalidator, NoopMemberPartialViewCacheInvalidator>();

src/Umbraco.Core/Cache/PartialViewCacheInvalidators/NoopMemberPartialViewCacheInvalidator.cs:3

  • [nitpick] It may help maintainability to add a brief XML doc comment on this class explaining its purpose and override behavior when .AddWebsite() is used.
internal class NoopMemberPartialViewCacheInvalidator : IMemberPartialViewCacheInvalidator

@Migaroez Migaroez merged commit 53cc663 into v13/dev Jul 8, 2025
19 of 20 checks passed
@Migaroez Migaroez deleted the v13/bugfix/ensure-implementation-of-IMemberPartialViewCacheInvalidator-is-registered branch July 8, 2025 13:40
AndyButland added a commit that referenced this pull request Jul 8, 2025
…n headless setups (#19666)

* Register no-op implementation of IMemberPartialViewCacheInvalidator in headless setups.

* Tidied usings.
# Conflicts:
#	src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs
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.

3 participants