From aa7e19e608dcc1e6f599df66132ecf4db2a28672 Mon Sep 17 00:00:00 2001 From: yv01p Date: Wed, 24 Dec 2025 19:03:05 +0000 Subject: [PATCH] refactor(core): remove obsolete constructors from ContentService MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove backward-compatibility constructors that used StaticServiceProvider for lazy resolution. All dependencies are now injected directly through the main constructor. Removed obsolete constructors: - Constructor with IAuditRepository parameter (legacy signature) - Constructor without Phase 2-7 service parameters (intermediate signature) Removed Lazy field declarations no longer needed: - _queryOperationServiceLazy - _versionOperationServiceLazy - _moveOperationServiceLazy - _publishOperationServiceLazy - _permissionManagerLazy - _blueprintManagerLazy Simplified service accessor properties to remove null checks for lazy fields (now only check the non-lazy field). BREAKING CHANGE: External code using obsolete constructors must update to use dependency injection. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/Umbraco.Core/Services/ContentService.cs | 214 +------------------- 1 file changed, 6 insertions(+), 208 deletions(-) diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index 788e35270f..575b186cd7 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -53,75 +53,39 @@ public class ContentService : RepositoryService, IContentService // Query operation service fields (for Phase 2 extracted query operations) private readonly IContentQueryOperationService? _queryOperationService; - private readonly Lazy? _queryOperationServiceLazy; // Version operation service fields (for Phase 3 extracted version operations) private readonly IContentVersionOperationService? _versionOperationService; - private readonly Lazy? _versionOperationServiceLazy; // Move operation service fields (for Phase 4 extracted move operations) 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; // Permission manager field (for Phase 6 extracted permission operations) private readonly ContentPermissionManager? _permissionManager; - private readonly Lazy? _permissionManagerLazy; // Blueprint manager field (for Phase 7 extracted blueprint operations) private readonly ContentBlueprintManager? _blueprintManager; - private readonly Lazy? _blueprintManagerLazy; - /// - /// Gets the query operation service. - /// - /// Thrown if the service was not properly initialized. private IContentQueryOperationService QueryOperationService => - _queryOperationService ?? _queryOperationServiceLazy?.Value - ?? throw new InvalidOperationException("QueryOperationService not initialized. Ensure the service is properly injected via constructor."); + _queryOperationService ?? throw new InvalidOperationException("QueryOperationService not initialized."); - /// - /// Gets the version operation service. - /// - /// Thrown if the service was not properly initialized. private IContentVersionOperationService VersionOperationService => - _versionOperationService ?? _versionOperationServiceLazy?.Value - ?? throw new InvalidOperationException("VersionOperationService not initialized. Ensure the service is properly injected via constructor."); + _versionOperationService ?? throw new InvalidOperationException("VersionOperationService not initialized."); - /// - /// Gets the move operation service. - /// - /// Thrown if the service was not properly initialized. private IContentMoveOperationService MoveOperationService => - _moveOperationService ?? _moveOperationServiceLazy?.Value - ?? throw new InvalidOperationException("MoveOperationService not initialized. Ensure the service is properly injected via constructor."); + _moveOperationService ?? throw new InvalidOperationException("MoveOperationService not initialized."); - /// - /// 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."); + _publishOperationService ?? throw new InvalidOperationException("PublishOperationService not initialized."); - /// - /// Gets the permission manager. - /// - /// Thrown if the manager was not properly initialized. private ContentPermissionManager PermissionManager => - _permissionManager ?? _permissionManagerLazy?.Value - ?? throw new InvalidOperationException("PermissionManager not initialized. Ensure the manager is properly injected via constructor."); + _permissionManager ?? throw new InvalidOperationException("PermissionManager not initialized."); - /// - /// Gets the blueprint manager. - /// - /// Thrown if the manager was not properly initialized. private ContentBlueprintManager BlueprintManager => - _blueprintManager ?? _blueprintManagerLazy?.Value - ?? throw new InvalidOperationException("BlueprintManager not initialized. Ensure the manager is properly injected via constructor."); + _blueprintManager ?? throw new InvalidOperationException("BlueprintManager not initialized."); #region Constructors @@ -179,194 +143,28 @@ public class ContentService : RepositoryService, IContentService // Phase 2: Query operation service (direct injection) ArgumentNullException.ThrowIfNull(queryOperationService); _queryOperationService = queryOperationService; - _queryOperationServiceLazy = null; // Not needed when directly injected // Phase 3: Version operation service (direct injection) ArgumentNullException.ThrowIfNull(versionOperationService); _versionOperationService = versionOperationService; - _versionOperationServiceLazy = null; // Not needed when directly injected // Phase 4: Move operation service (direct injection) 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 // Phase 6: Permission manager (direct injection) ArgumentNullException.ThrowIfNull(permissionManager); _permissionManager = permissionManager; - _permissionManagerLazy = null; // Not needed when directly injected // Phase 7: Blueprint manager (direct injection) ArgumentNullException.ThrowIfNull(blueprintManager); _blueprintManager = blueprintManager; - _blueprintManagerLazy = null; // Not needed when directly injected } - [Obsolete("Use the non-obsolete constructor instead. Scheduled removal in v19.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public ContentService( - ICoreScopeProvider provider, - ILoggerFactory loggerFactory, - IEventMessagesFactory eventMessagesFactory, - IDocumentRepository documentRepository, - IEntityRepository entityRepository, - IAuditRepository auditRepository, // Old parameter (kept for signature compatibility) - IContentTypeRepository contentTypeRepository, - IDocumentBlueprintRepository documentBlueprintRepository, - ILanguageRepository languageRepository, - Lazy propertyValidationService, - IShortStringHelper shortStringHelper, - ICultureImpactFactory cultureImpactFactory, - IUserIdKeyResolver userIdKeyResolver, - PropertyEditorCollection propertyEditorCollection, - IIdKeyMap idKeyMap, - IOptionsMonitor optionsMonitor, - IRelationService relationService) - : base(provider, loggerFactory, eventMessagesFactory) - { - // All existing field assignments... - _documentRepository = documentRepository ?? throw new ArgumentNullException(nameof(documentRepository)); - _entityRepository = entityRepository ?? throw new ArgumentNullException(nameof(entityRepository)); - _contentTypeRepository = contentTypeRepository ?? throw new ArgumentNullException(nameof(contentTypeRepository)); - _documentBlueprintRepository = documentBlueprintRepository ?? throw new ArgumentNullException(nameof(documentBlueprintRepository)); - _languageRepository = languageRepository ?? throw new ArgumentNullException(nameof(languageRepository)); - _propertyValidationService = propertyValidationService ?? throw new ArgumentNullException(nameof(propertyValidationService)); - _shortStringHelper = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper)); - _cultureImpactFactory = cultureImpactFactory ?? throw new ArgumentNullException(nameof(cultureImpactFactory)); - _userIdKeyResolver = userIdKeyResolver ?? throw new ArgumentNullException(nameof(userIdKeyResolver)); - _propertyEditorCollection = propertyEditorCollection ?? throw new ArgumentNullException(nameof(propertyEditorCollection)); - _idKeyMap = idKeyMap ?? throw new ArgumentNullException(nameof(idKeyMap)); - _contentSettings = optionsMonitor?.CurrentValue ?? throw new ArgumentNullException(nameof(optionsMonitor)); - optionsMonitor.OnChange((contentSettings) => - { - _contentSettings = contentSettings; - }); - _relationService = relationService ?? throw new ArgumentNullException(nameof(relationService)); - _logger = loggerFactory.CreateLogger(); - - // Lazy resolution of IAuditService (from StaticServiceProvider) - _auditService = StaticServiceProvider.Instance.GetRequiredService(); - - // NEW: Lazy resolution of IContentCrudService - _crudServiceLazy = new Lazy(() => - StaticServiceProvider.Instance.GetRequiredService(), - LazyThreadSafetyMode.ExecutionAndPublication); - - // Phase 2: Lazy resolution of IContentQueryOperationService - _queryOperationServiceLazy = new Lazy(() => - StaticServiceProvider.Instance.GetRequiredService(), - LazyThreadSafetyMode.ExecutionAndPublication); - - // Phase 3: Lazy resolution of IContentVersionOperationService - _versionOperationServiceLazy = new Lazy(() => - StaticServiceProvider.Instance.GetRequiredService(), - LazyThreadSafetyMode.ExecutionAndPublication); - - // Phase 4: Lazy resolution of IContentMoveOperationService - _moveOperationServiceLazy = new Lazy(() => - StaticServiceProvider.Instance.GetRequiredService(), - LazyThreadSafetyMode.ExecutionAndPublication); - - // Phase 5: Lazy resolution of IContentPublishOperationService - _publishOperationServiceLazy = new Lazy(() => - StaticServiceProvider.Instance.GetRequiredService(), - LazyThreadSafetyMode.ExecutionAndPublication); - - // Phase 6: Lazy resolution of ContentPermissionManager - _permissionManagerLazy = new Lazy(() => - StaticServiceProvider.Instance.GetRequiredService(), - LazyThreadSafetyMode.ExecutionAndPublication); - - // Phase 7: Lazy resolution of ContentBlueprintManager - _blueprintManagerLazy = new Lazy(() => - StaticServiceProvider.Instance.GetRequiredService(), - LazyThreadSafetyMode.ExecutionAndPublication); - } - - [Obsolete("Use the non-obsolete constructor instead. Scheduled removal in v19.")] - [EditorBrowsable(EditorBrowsableState.Never)] - public ContentService( - ICoreScopeProvider provider, - ILoggerFactory loggerFactory, - IEventMessagesFactory eventMessagesFactory, - IDocumentRepository documentRepository, - IEntityRepository entityRepository, - IAuditRepository auditRepository, // Old parameter (kept for signature compatibility) - IAuditService auditService, - IContentTypeRepository contentTypeRepository, - IDocumentBlueprintRepository documentBlueprintRepository, - ILanguageRepository languageRepository, - Lazy propertyValidationService, - IShortStringHelper shortStringHelper, - ICultureImpactFactory cultureImpactFactory, - IUserIdKeyResolver userIdKeyResolver, - PropertyEditorCollection propertyEditorCollection, - IIdKeyMap idKeyMap, - IOptionsMonitor optionsMonitor, - IRelationService relationService) - : base(provider, loggerFactory, eventMessagesFactory) - { - // All existing field assignments... - _documentRepository = documentRepository ?? throw new ArgumentNullException(nameof(documentRepository)); - _entityRepository = entityRepository ?? throw new ArgumentNullException(nameof(entityRepository)); - _auditService = auditService ?? throw new ArgumentNullException(nameof(auditService)); - _contentTypeRepository = contentTypeRepository ?? throw new ArgumentNullException(nameof(contentTypeRepository)); - _documentBlueprintRepository = documentBlueprintRepository ?? throw new ArgumentNullException(nameof(documentBlueprintRepository)); - _languageRepository = languageRepository ?? throw new ArgumentNullException(nameof(languageRepository)); - _propertyValidationService = propertyValidationService ?? throw new ArgumentNullException(nameof(propertyValidationService)); - _shortStringHelper = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper)); - _cultureImpactFactory = cultureImpactFactory ?? throw new ArgumentNullException(nameof(cultureImpactFactory)); - _userIdKeyResolver = userIdKeyResolver ?? throw new ArgumentNullException(nameof(userIdKeyResolver)); - _propertyEditorCollection = propertyEditorCollection ?? throw new ArgumentNullException(nameof(propertyEditorCollection)); - _idKeyMap = idKeyMap ?? throw new ArgumentNullException(nameof(idKeyMap)); - _contentSettings = optionsMonitor?.CurrentValue ?? throw new ArgumentNullException(nameof(optionsMonitor)); - optionsMonitor.OnChange((contentSettings) => - { - _contentSettings = contentSettings; - }); - _relationService = relationService ?? throw new ArgumentNullException(nameof(relationService)); - _logger = loggerFactory.CreateLogger(); - - // NEW: Lazy resolution of IContentCrudService - _crudServiceLazy = new Lazy(() => - StaticServiceProvider.Instance.GetRequiredService(), - LazyThreadSafetyMode.ExecutionAndPublication); - - // Phase 2: Lazy resolution of IContentQueryOperationService - _queryOperationServiceLazy = new Lazy(() => - StaticServiceProvider.Instance.GetRequiredService(), - LazyThreadSafetyMode.ExecutionAndPublication); - - // Phase 3: Lazy resolution of IContentVersionOperationService - _versionOperationServiceLazy = new Lazy(() => - StaticServiceProvider.Instance.GetRequiredService(), - LazyThreadSafetyMode.ExecutionAndPublication); - - // Phase 4: Lazy resolution of IContentMoveOperationService - _moveOperationServiceLazy = new Lazy(() => - StaticServiceProvider.Instance.GetRequiredService(), - LazyThreadSafetyMode.ExecutionAndPublication); - - // Phase 5: Lazy resolution of IContentPublishOperationService - _publishOperationServiceLazy = new Lazy(() => - StaticServiceProvider.Instance.GetRequiredService(), - LazyThreadSafetyMode.ExecutionAndPublication); - - // Phase 6: Lazy resolution of ContentPermissionManager - _permissionManagerLazy = new Lazy(() => - StaticServiceProvider.Instance.GetRequiredService(), - LazyThreadSafetyMode.ExecutionAndPublication); - - // Phase 7: Lazy resolution of ContentBlueprintManager - _blueprintManagerLazy = new Lazy(() => - StaticServiceProvider.Instance.GetRequiredService(), - LazyThreadSafetyMode.ExecutionAndPublication); - } #endregion