From ea4602ec150b70e1f7b69273a51b8d8ac52f7f18 Mon Sep 17 00:00:00 2001 From: yv01p Date: Tue, 23 Dec 2025 19:58:11 +0000 Subject: [PATCH] refactor(core): add IContentPublishOperationService injection to ContentService Adds field, property, and constructor parameter for the new publish operation service. Obsolete constructors use lazy resolution for backward compatibility. Part of ContentService refactoring Phase 5. --- src/Umbraco.Core/Services/ContentService.cs | 30 ++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index a580e0c90d..6bde9c7068 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -63,6 +63,10 @@ public class ContentService : RepositoryService, IContentService private readonly IContentMoveOperationService? _moveOperationService; private readonly Lazy? _moveOperationServiceLazy; + // Publish operation service fields (for Phase 5 extracted publish operations) + private readonly IContentPublishOperationService? _publishOperationService; + private readonly Lazy? _publishOperationServiceLazy; + /// /// Gets the query operation service. /// @@ -87,6 +91,14 @@ public class ContentService : RepositoryService, IContentService _moveOperationService ?? _moveOperationServiceLazy?.Value ?? throw new InvalidOperationException("MoveOperationService not initialized. Ensure the service is properly injected via constructor."); + /// + /// Gets the publish operation service. + /// + /// Thrown if the service was not properly initialized. + private IContentPublishOperationService PublishOperationService => + _publishOperationService ?? _publishOperationServiceLazy?.Value + ?? throw new InvalidOperationException("PublishOperationService not initialized. Ensure the service is properly injected via constructor."); + #region Constructors [Microsoft.Extensions.DependencyInjection.ActivatorUtilitiesConstructor] @@ -111,7 +123,8 @@ public class ContentService : RepositoryService, IContentService IContentCrudService crudService, IContentQueryOperationService queryOperationService, // NEW PARAMETER - Phase 2 query operations IContentVersionOperationService versionOperationService, // NEW PARAMETER - Phase 3 version operations - IContentMoveOperationService moveOperationService) // NEW PARAMETER - Phase 4 move operations + IContentMoveOperationService moveOperationService, // NEW PARAMETER - Phase 4 move operations + IContentPublishOperationService publishOperationService) // NEW PARAMETER - Phase 5 publish operations : base(provider, loggerFactory, eventMessagesFactory) { _documentRepository = documentRepository; @@ -151,6 +164,11 @@ public class ContentService : RepositoryService, IContentService ArgumentNullException.ThrowIfNull(moveOperationService); _moveOperationService = moveOperationService; _moveOperationServiceLazy = null; // Not needed when directly injected + + // Phase 5: Publish operation service (direct injection) + ArgumentNullException.ThrowIfNull(publishOperationService); + _publishOperationService = publishOperationService; + _publishOperationServiceLazy = null; // Not needed when directly injected } [Obsolete("Use the non-obsolete constructor instead. Scheduled removal in v19.")] @@ -217,6 +235,11 @@ public class ContentService : RepositoryService, IContentService _moveOperationServiceLazy = new Lazy(() => StaticServiceProvider.Instance.GetRequiredService(), LazyThreadSafetyMode.ExecutionAndPublication); + + // Phase 5: Lazy resolution of IContentPublishOperationService + _publishOperationServiceLazy = new Lazy(() => + StaticServiceProvider.Instance.GetRequiredService(), + LazyThreadSafetyMode.ExecutionAndPublication); } [Obsolete("Use the non-obsolete constructor instead. Scheduled removal in v19.")] @@ -282,6 +305,11 @@ public class ContentService : RepositoryService, IContentService _moveOperationServiceLazy = new Lazy(() => StaticServiceProvider.Instance.GetRequiredService(), LazyThreadSafetyMode.ExecutionAndPublication); + + // Phase 5: Lazy resolution of IContentPublishOperationService + _publishOperationServiceLazy = new Lazy(() => + StaticServiceProvider.Instance.GetRequiredService(), + LazyThreadSafetyMode.ExecutionAndPublication); } #endregion