diff --git a/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/AncestorsPartialViewTreeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/AncestorsPartialViewTreeController.cs index 3f79545e3950..6f30a7268482 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/AncestorsPartialViewTreeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/AncestorsPartialViewTreeController.cs @@ -1,34 +1,32 @@ -using Asp.Versioning; +using Asp.Versioning; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.Tree; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Api.Management.Controllers.PartialView.Tree; [ApiVersion("1.0")] public class AncestorsPartialViewTreeController : PartialViewTreeControllerBase { - private readonly IPartialViewTreeService _partialViewTreeService; - // TODO Remove the static service provider, and replace with base when the other constructors are obsoleted. + [ActivatorUtilitiesConstructor] public AncestorsPartialViewTreeController(IPartialViewTreeService partialViewTreeService) - : this(partialViewTreeService, StaticServiceProvider.Instance.GetRequiredService()) - => _partialViewTreeService = partialViewTreeService; + : base(partialViewTreeService) + { + } - [ActivatorUtilitiesConstructor] - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public AncestorsPartialViewTreeController(IPartialViewTreeService partialViewTreeService, FileSystems fileSystems) - : base(partialViewTreeService, fileSystems) => - _partialViewTreeService = partialViewTreeService; + : base(partialViewTreeService, fileSystems) + { + } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public AncestorsPartialViewTreeController(FileSystems fileSystems) - : this(StaticServiceProvider.Instance.GetRequiredService(), fileSystems) + : base(fileSystems) { } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/ChildrenPartialViewTreeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/ChildrenPartialViewTreeController.cs index 099f01f3422d..9c70e7acbed4 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/ChildrenPartialViewTreeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/ChildrenPartialViewTreeController.cs @@ -1,34 +1,33 @@ -using Asp.Versioning; +using Asp.Versioning; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.IO; using Umbraco.Cms.Api.Common.ViewModels.Pagination; using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.Tree; -using Umbraco.Cms.Core.DependencyInjection; +using Umbraco.Cms.Core.IO; namespace Umbraco.Cms.Api.Management.Controllers.PartialView.Tree; [ApiVersion("1.0")] public class ChildrenPartialViewTreeController : PartialViewTreeControllerBase { - private readonly IPartialViewTreeService _partialViewTreeService; - // TODO Remove the static service provider, and replace with base when the other constructors are obsoleted. + [ActivatorUtilitiesConstructor] public ChildrenPartialViewTreeController(IPartialViewTreeService partialViewTreeService) - : this(partialViewTreeService, StaticServiceProvider.Instance.GetRequiredService()) - => _partialViewTreeService = partialViewTreeService; + : base(partialViewTreeService) + { + } - [ActivatorUtilitiesConstructor] - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public ChildrenPartialViewTreeController(IPartialViewTreeService partialViewTreeService, FileSystems fileSystems) - : base(partialViewTreeService, fileSystems) => - _partialViewTreeService = partialViewTreeService; + : base(partialViewTreeService, fileSystems) + { + } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public ChildrenPartialViewTreeController(FileSystems fileSystems) - : this(StaticServiceProvider.Instance.GetRequiredService(), fileSystems) + : base(fileSystems) { } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/PartialViewTreeControllerBase.cs b/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/PartialViewTreeControllerBase.cs index 6875e395f640..5f50a098983b 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/PartialViewTreeControllerBase.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/PartialViewTreeControllerBase.cs @@ -1,11 +1,9 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Api.Management.Controllers.Tree; using Umbraco.Cms.Api.Management.Routing; using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Core; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Web.Common.Authorization; @@ -16,30 +14,28 @@ namespace Umbraco.Cms.Api.Management.Controllers.PartialView.Tree; [Authorize(Policy = AuthorizationPolicies.TreeAccessPartialViews)] public class PartialViewTreeControllerBase : FileSystemTreeControllerBase { - private readonly IPartialViewTreeService _partialViewTreeService; - // TODO Remove the static service provider, and replace with base when the other constructors are obsoleted. public PartialViewTreeControllerBase(IPartialViewTreeService partialViewTreeService) - : this(partialViewTreeService, StaticServiceProvider.Instance.GetRequiredService()) => - _partialViewTreeService = partialViewTreeService; + : base(partialViewTreeService) + { + FileSystem = null!; + } - // FileSystem is required therefore, we can't remove it without some wizadry. When obsoletion is due, remove this. - [ActivatorUtilitiesConstructor] - [Obsolete("Scheduled for removal in Umbraco 18.")] + // FileSystem is required therefore, we can't remove it without some wizardry. When obsoletion is due, remove this. + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public PartialViewTreeControllerBase(IPartialViewTreeService partialViewTreeService, FileSystems fileSystems) : base(partialViewTreeService) { - _partialViewTreeService = partialViewTreeService; FileSystem = fileSystems.PartialViewsFileSystem ?? throw new ArgumentException("Missing scripts file system", nameof(fileSystems)); } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 18.")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public PartialViewTreeControllerBase(FileSystems fileSystems) - : this(StaticServiceProvider.Instance.GetRequiredService()) + : base() => FileSystem = fileSystems.PartialViewsFileSystem ?? throw new ArgumentException("Missing scripts file system", nameof(fileSystems)); - [Obsolete("Included in the service class. Scheduled to be removed in Umbraco 18.")] + [Obsolete("Included in the service class. Scheduled to be removed in Umbraco 19.")] protected override IFileSystem FileSystem { get; } } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/RootPartialViewTreeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/RootPartialViewTreeController.cs index 4e42266389f7..0a7d95627f87 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/RootPartialViewTreeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/RootPartialViewTreeController.cs @@ -1,34 +1,33 @@ -using Asp.Versioning; +using Asp.Versioning; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.IO; using Umbraco.Cms.Api.Common.ViewModels.Pagination; using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.Tree; -using Umbraco.Cms.Core.DependencyInjection; +using Umbraco.Cms.Core.IO; namespace Umbraco.Cms.Api.Management.Controllers.PartialView.Tree; [ApiVersion("1.0")] public class RootPartialViewTreeController : PartialViewTreeControllerBase { - private readonly IPartialViewTreeService _partialViewTreeService; - // TODO Remove the static service provider, and replace with base when the other constructors are obsoleted. + [ActivatorUtilitiesConstructor] public RootPartialViewTreeController(IPartialViewTreeService partialViewTreeService) - : this(partialViewTreeService, StaticServiceProvider.Instance.GetRequiredService()) - => _partialViewTreeService = partialViewTreeService; + : base(partialViewTreeService) + { + } - [ActivatorUtilitiesConstructor] - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public RootPartialViewTreeController(IPartialViewTreeService partialViewTreeService, FileSystems fileSystems) - : base(partialViewTreeService, fileSystems) => - _partialViewTreeService = partialViewTreeService; + : base(partialViewTreeService, fileSystems) + { + } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public RootPartialViewTreeController(FileSystems fileSystems) - : this(StaticServiceProvider.Instance.GetRequiredService(), fileSystems) + : base(fileSystems) { } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/SiblingsPartialViewTreeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/SiblingsPartialViewTreeController.cs index af1e3171a643..8b3354d0f663 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/SiblingsPartialViewTreeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/SiblingsPartialViewTreeController.cs @@ -1,32 +1,31 @@ -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Api.Common.ViewModels.Pagination; using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.Tree; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; namespace Umbraco.Cms.Api.Management.Controllers.PartialView.Tree; public class SiblingsPartialViewTreeController : PartialViewTreeControllerBase { - private readonly IPartialViewTreeService _partialViewTreeService; - // TODO Remove the static service provider, and replace with base when the other constructors are obsoleted. + [ActivatorUtilitiesConstructor] public SiblingsPartialViewTreeController(IPartialViewTreeService partialViewTreeService) - : this(partialViewTreeService, StaticServiceProvider.Instance.GetRequiredService()) - => _partialViewTreeService = partialViewTreeService; + : base(partialViewTreeService) + { + } - [ActivatorUtilitiesConstructor] - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public SiblingsPartialViewTreeController(IPartialViewTreeService partialViewTreeService, FileSystems fileSystems) - : base(partialViewTreeService, fileSystems) => - _partialViewTreeService = partialViewTreeService; + : base(partialViewTreeService, fileSystems) + { + } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public SiblingsPartialViewTreeController(FileSystems fileSystems) - : this(StaticServiceProvider.Instance.GetRequiredService(), fileSystems) + : base(fileSystems) { } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/AncestorsScriptTreeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/AncestorsScriptTreeController.cs index ed5acbc0c356..0aef76c5b782 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/AncestorsScriptTreeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/AncestorsScriptTreeController.cs @@ -1,10 +1,9 @@ -using Asp.Versioning; +using Asp.Versioning; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.Tree; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; namespace Umbraco.Cms.Api.Management.Controllers.Script.Tree; @@ -12,22 +11,22 @@ namespace Umbraco.Cms.Api.Management.Controllers.Script.Tree; [ApiVersion("1.0")] public class AncestorsScriptTreeController : ScriptTreeControllerBase { - private readonly IScriptTreeService _scriptTreeService; - // TODO Remove the static service provider, and replace with base when the other constructors are obsoleted. + [ActivatorUtilitiesConstructor] public AncestorsScriptTreeController(IScriptTreeService scriptTreeService) - : this(scriptTreeService, StaticServiceProvider.Instance.GetRequiredService()) - => _scriptTreeService = scriptTreeService; + : base(scriptTreeService) + { + } - [ActivatorUtilitiesConstructor] - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public AncestorsScriptTreeController(IScriptTreeService scriptTreeService, FileSystems fileSystems) - : base(scriptTreeService, fileSystems) => - _scriptTreeService = scriptTreeService; + : base(scriptTreeService, fileSystems) + { + } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public AncestorsScriptTreeController(FileSystems fileSystems) - : this(StaticServiceProvider.Instance.GetRequiredService(), fileSystems) + : base(fileSystems) { } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/ChildrenScriptTreeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/ChildrenScriptTreeController.cs index ba4003784142..8313b6294139 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/ChildrenScriptTreeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/ChildrenScriptTreeController.cs @@ -1,34 +1,33 @@ -using Asp.Versioning; +using Asp.Versioning; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.IO; using Umbraco.Cms.Api.Common.ViewModels.Pagination; using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.Tree; -using Umbraco.Cms.Core.DependencyInjection; +using Umbraco.Cms.Core.IO; namespace Umbraco.Cms.Api.Management.Controllers.Script.Tree; [ApiVersion("1.0")] public class ChildrenScriptTreeController : ScriptTreeControllerBase { - private readonly IScriptTreeService _scriptTreeService; - // TODO Remove the static service provider, and replace with base when the other constructors are obsoleted. + [ActivatorUtilitiesConstructor] public ChildrenScriptTreeController(IScriptTreeService scriptTreeService) - : this(scriptTreeService, StaticServiceProvider.Instance.GetRequiredService()) - => _scriptTreeService = scriptTreeService; + : base(scriptTreeService) + { + } - [ActivatorUtilitiesConstructor] - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public ChildrenScriptTreeController(IScriptTreeService scriptTreeService, FileSystems fileSystems) - : base(scriptTreeService, fileSystems) => - _scriptTreeService = scriptTreeService; + : base(scriptTreeService, fileSystems) + { + } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public ChildrenScriptTreeController(FileSystems fileSystems) - : this(StaticServiceProvider.Instance.GetRequiredService(), fileSystems) + : base(fileSystems) { } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/RootScriptTreeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/RootScriptTreeController.cs index f29d3bdb4401..dcb5e2479ced 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/RootScriptTreeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/RootScriptTreeController.cs @@ -1,34 +1,33 @@ -using Asp.Versioning; +using Asp.Versioning; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.IO; using Umbraco.Cms.Api.Common.ViewModels.Pagination; using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.Tree; -using Umbraco.Cms.Core.DependencyInjection; +using Umbraco.Cms.Core.IO; namespace Umbraco.Cms.Api.Management.Controllers.Script.Tree; [ApiVersion("1.0")] public class RootScriptTreeController : ScriptTreeControllerBase { - private readonly IScriptTreeService _scriptTreeService; - // TODO Remove the static service provider, and replace with base when the other constructors are obsoleted. + [ActivatorUtilitiesConstructor] public RootScriptTreeController(IScriptTreeService scriptTreeService) - : this(scriptTreeService, StaticServiceProvider.Instance.GetRequiredService()) - => _scriptTreeService = scriptTreeService; + : base(scriptTreeService) + { + } - [ActivatorUtilitiesConstructor] - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public RootScriptTreeController(IScriptTreeService scriptTreeService, FileSystems fileSystems) - : base(scriptTreeService, fileSystems) => - _scriptTreeService = scriptTreeService; + : base(scriptTreeService, fileSystems) + { + } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public RootScriptTreeController(FileSystems fileSystems) - : this(StaticServiceProvider.Instance.GetRequiredService(), fileSystems) + : base(fileSystems) { } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/ScriptTreeControllerBase.cs b/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/ScriptTreeControllerBase.cs index d79740d845e3..f803db096fd4 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/ScriptTreeControllerBase.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/ScriptTreeControllerBase.cs @@ -1,11 +1,9 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Api.Management.Controllers.Tree; using Umbraco.Cms.Api.Management.Routing; using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Core; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Web.Common.Authorization; @@ -16,30 +14,28 @@ namespace Umbraco.Cms.Api.Management.Controllers.Script.Tree; [Authorize(Policy = AuthorizationPolicies.TreeAccessScripts)] public class ScriptTreeControllerBase : FileSystemTreeControllerBase { - private readonly IScriptTreeService _scriptTreeService; - // TODO Remove the static service provider, and replace with base when the other constructors are obsoleted. public ScriptTreeControllerBase(IScriptTreeService scriptTreeService) - : this(scriptTreeService, StaticServiceProvider.Instance.GetRequiredService()) => - _scriptTreeService = scriptTreeService; + : base(scriptTreeService) + { + FileSystem = null!; + } - // FileSystem is required therefore, we can't remove it without some wizadry. When obsoletion is due, remove this. - [ActivatorUtilitiesConstructor] - [Obsolete("Scheduled for removal in Umbraco 18.")] + // FileSystem is required therefore, we can't remove it without some wizardry. When obsoletion is due, remove this. + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public ScriptTreeControllerBase(IScriptTreeService scriptTreeService, FileSystems fileSystems) : base(scriptTreeService) { - _scriptTreeService = scriptTreeService; FileSystem = fileSystems.ScriptsFileSystem ?? throw new ArgumentException("Missing scripts file system", nameof(fileSystems)); } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 18.")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public ScriptTreeControllerBase(FileSystems fileSystems) - : this(StaticServiceProvider.Instance.GetRequiredService()) + : base() => FileSystem = fileSystems.ScriptsFileSystem ?? throw new ArgumentException("Missing scripts file system", nameof(fileSystems)); - [Obsolete("Included in the service class. Scheduled to be removed in Umbraco 18.")] + [Obsolete("Included in the service class. Scheduled to be removed in Umbraco 19.")] protected override IFileSystem FileSystem { get; } } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/SiblingsScriptTreeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/SiblingsScriptTreeController.cs index deec60cacb8e..fa53cfa77473 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/SiblingsScriptTreeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/SiblingsScriptTreeController.cs @@ -1,32 +1,31 @@ -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Api.Common.ViewModels.Pagination; using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.Tree; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; namespace Umbraco.Cms.Api.Management.Controllers.Script.Tree; public class SiblingsScriptTreeController : ScriptTreeControllerBase { - private readonly IScriptTreeService _scriptTreeService; - // TODO Remove the static service provider, and replace with base when the other constructors are obsoleted. + [ActivatorUtilitiesConstructor] public SiblingsScriptTreeController(IScriptTreeService scriptTreeService) - : this(scriptTreeService, StaticServiceProvider.Instance.GetRequiredService()) - => _scriptTreeService = scriptTreeService; + : base(scriptTreeService) + { + } - [ActivatorUtilitiesConstructor] - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public SiblingsScriptTreeController(IScriptTreeService scriptTreeService, FileSystems fileSystems) - : base(scriptTreeService, fileSystems) => - _scriptTreeService = scriptTreeService; + : base(scriptTreeService, fileSystems) + { + } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public SiblingsScriptTreeController(FileSystems fileSystems) - : this(StaticServiceProvider.Instance.GetRequiredService(), fileSystems) + : base(fileSystems) { } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/AncestorsStylesheetTreeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/AncestorsStylesheetTreeController.cs index 3760808263bf..2663152f4c6a 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/AncestorsStylesheetTreeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/AncestorsStylesheetTreeController.cs @@ -1,10 +1,9 @@ -using Asp.Versioning; +using Asp.Versioning; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.Tree; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; namespace Umbraco.Cms.Api.Management.Controllers.Stylesheet.Tree; @@ -12,22 +11,22 @@ namespace Umbraco.Cms.Api.Management.Controllers.Stylesheet.Tree; [ApiVersion("1.0")] public class AncestorsStylesheetTreeController : StylesheetTreeControllerBase { - private readonly IStyleSheetTreeService _styleSheetTreeService; - // TODO Remove the static service provider, and replace with base when the other constructors are obsoleted. + [ActivatorUtilitiesConstructor] public AncestorsStylesheetTreeController(IStyleSheetTreeService styleSheetTreeService) - : this(styleSheetTreeService, StaticServiceProvider.Instance.GetRequiredService()) - => _styleSheetTreeService = styleSheetTreeService; + : base(styleSheetTreeService) + { + } - [ActivatorUtilitiesConstructor] - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public AncestorsStylesheetTreeController(IStyleSheetTreeService styleSheetTreeService, FileSystems fileSystems) - : base(styleSheetTreeService, fileSystems) => - _styleSheetTreeService = styleSheetTreeService; + : base(styleSheetTreeService, fileSystems) + { + } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public AncestorsStylesheetTreeController(FileSystems fileSystems) - : this(StaticServiceProvider.Instance.GetRequiredService(), fileSystems) + : base(fileSystems) { } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/ChildrenStylesheetTreeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/ChildrenStylesheetTreeController.cs index 41484bce50ec..bf016b54e39f 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/ChildrenStylesheetTreeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/ChildrenStylesheetTreeController.cs @@ -1,36 +1,36 @@ -using Asp.Versioning; +using Asp.Versioning; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.IO; using Umbraco.Cms.Api.Common.ViewModels.Pagination; using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.Tree; -using Umbraco.Cms.Core.DependencyInjection; +using Umbraco.Cms.Core.IO; namespace Umbraco.Cms.Api.Management.Controllers.Stylesheet.Tree; [ApiVersion("1.0")] public class ChildrenStylesheetTreeController : StylesheetTreeControllerBase { - private readonly IStyleSheetTreeService _styleSheetTreeService; - // TODO Remove the static service provider, and replace with base when the other constructors are obsoleted. + [ActivatorUtilitiesConstructor] public ChildrenStylesheetTreeController(IStyleSheetTreeService styleSheetTreeService) - : this(styleSheetTreeService, StaticServiceProvider.Instance.GetRequiredService()) - => _styleSheetTreeService = styleSheetTreeService; + : base(styleSheetTreeService) + { + } - [ActivatorUtilitiesConstructor] - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public ChildrenStylesheetTreeController(IStyleSheetTreeService styleSheetTreeService, FileSystems fileSystems) - : base(styleSheetTreeService, fileSystems) => - _styleSheetTreeService = styleSheetTreeService; + : base(styleSheetTreeService, fileSystems) + { + } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public ChildrenStylesheetTreeController(FileSystems fileSystems) - : this(StaticServiceProvider.Instance.GetRequiredService(), fileSystems) + : base(fileSystems) { } + [HttpGet("children")] [MapToApiVersion("1.0")] [ProducesResponseType(typeof(PagedViewModel), StatusCodes.Status200OK)] diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/RootStylesheetTreeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/RootStylesheetTreeController.cs index 417c636a375d..c47828d09228 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/RootStylesheetTreeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/RootStylesheetTreeController.cs @@ -1,34 +1,33 @@ -using Asp.Versioning; +using Asp.Versioning; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.IO; using Umbraco.Cms.Api.Common.ViewModels.Pagination; using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.Tree; -using Umbraco.Cms.Core.DependencyInjection; +using Umbraco.Cms.Core.IO; namespace Umbraco.Cms.Api.Management.Controllers.Stylesheet.Tree; [ApiVersion("1.0")] public class RootStylesheetTreeController : StylesheetTreeControllerBase { - private readonly IStyleSheetTreeService _styleSheetTreeService; - // TODO Remove the static service provider, and replace with base when the other constructors are obsoleted. + [ActivatorUtilitiesConstructor] public RootStylesheetTreeController(IStyleSheetTreeService styleSheetTreeService) - : this(styleSheetTreeService, StaticServiceProvider.Instance.GetRequiredService()) - => _styleSheetTreeService = styleSheetTreeService; + : base(styleSheetTreeService) + { + } - [ActivatorUtilitiesConstructor] - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public RootStylesheetTreeController(IStyleSheetTreeService styleSheetTreeService, FileSystems fileSystems) - : base(styleSheetTreeService, fileSystems) => - _styleSheetTreeService = styleSheetTreeService; + : base(styleSheetTreeService, fileSystems) + { + } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public RootStylesheetTreeController(FileSystems fileSystems) - : this(StaticServiceProvider.Instance.GetRequiredService(), fileSystems) + : base(fileSystems) { } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/SiblingsStylesheetTreeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/SiblingsStylesheetTreeController.cs index 0f2b03b704d9..b56afe70b775 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/SiblingsStylesheetTreeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/SiblingsStylesheetTreeController.cs @@ -1,32 +1,31 @@ -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Api.Common.ViewModels.Pagination; using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.Tree; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; namespace Umbraco.Cms.Api.Management.Controllers.Stylesheet.Tree; public class SiblingsStylesheetTreeController : StylesheetTreeControllerBase { - private readonly IStyleSheetTreeService _styleSheetTreeService; - // TODO Remove the static service provider, and replace with base when the other constructors are obsoleted. + [ActivatorUtilitiesConstructor] public SiblingsStylesheetTreeController(IStyleSheetTreeService styleSheetTreeService) - : this(styleSheetTreeService, StaticServiceProvider.Instance.GetRequiredService()) - => _styleSheetTreeService = styleSheetTreeService; + : base(styleSheetTreeService) + { + } - [ActivatorUtilitiesConstructor] - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public SiblingsStylesheetTreeController(IStyleSheetTreeService styleSheetTreeService, FileSystems fileSystems) - : base(styleSheetTreeService, fileSystems) => - _styleSheetTreeService = styleSheetTreeService; + : base(styleSheetTreeService, fileSystems) + { + } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public SiblingsStylesheetTreeController(FileSystems fileSystems) - : this(StaticServiceProvider.Instance.GetRequiredService(), fileSystems) + : base(fileSystems) { } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/StylesheetTreeControllerBase.cs b/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/StylesheetTreeControllerBase.cs index 501293f11fa4..07382a145399 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/StylesheetTreeControllerBase.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/StylesheetTreeControllerBase.cs @@ -1,11 +1,9 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Api.Management.Controllers.Tree; using Umbraco.Cms.Api.Management.Routing; using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Core; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Web.Common.Authorization; @@ -16,30 +14,28 @@ namespace Umbraco.Cms.Api.Management.Controllers.Stylesheet.Tree; [Authorize(Policy = AuthorizationPolicies.TreeAccessStylesheets)] public class StylesheetTreeControllerBase : FileSystemTreeControllerBase { - private readonly IStyleSheetTreeService _styleSheetTreeService; - // TODO Remove the static service provider, and replace with base when the other constructors are obsoleted. public StylesheetTreeControllerBase(IStyleSheetTreeService styleSheetTreeService) - : this(styleSheetTreeService, StaticServiceProvider.Instance.GetRequiredService()) => - _styleSheetTreeService = styleSheetTreeService; + : base(styleSheetTreeService) + { + FileSystem = null!; + } // FileSystem is required therefore, we can't remove it without some wizadry. When obsoletion is due, remove this. - [ActivatorUtilitiesConstructor] - [Obsolete("Scheduled for removal in Umbraco 18.")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public StylesheetTreeControllerBase(IStyleSheetTreeService styleSheetTreeService, FileSystems fileSystems) : base(styleSheetTreeService) { - _styleSheetTreeService = styleSheetTreeService; FileSystem = fileSystems.ScriptsFileSystem ?? throw new ArgumentException("Missing scripts file system", nameof(fileSystems)); } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 18.")] + [Obsolete("Please use the constructor taking all parameters. Scheduled to be removed in Umbraco 19.")] public StylesheetTreeControllerBase(FileSystems fileSystems) - : this(StaticServiceProvider.Instance.GetRequiredService()) + : base() => FileSystem = fileSystems.ScriptsFileSystem ?? throw new ArgumentException("Missing scripts file system", nameof(fileSystems)); - [Obsolete("Included in the service class. Scheduled to be removed in Umbraco 18.")] + [Obsolete("Included in the service class. Scheduled to be removed in Umbraco 19.")] protected override IFileSystem FileSystem { get; } } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Tree/FileSystemTreeControllerBase.cs b/src/Umbraco.Cms.Api.Management/Controllers/Tree/FileSystemTreeControllerBase.cs index 68d1414788fb..fa3b2027b35d 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Tree/FileSystemTreeControllerBase.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Tree/FileSystemTreeControllerBase.cs @@ -5,7 +5,6 @@ using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.Tree; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Extensions; @@ -13,23 +12,30 @@ namespace Umbraco.Cms.Api.Management.Controllers.Tree; public abstract class FileSystemTreeControllerBase : ManagementApiControllerBase { - private readonly IFileSystemTreeService _fileSystemTreeService; + private readonly IFileSystemTreeService _fileSystemTreeService = null!; - [Obsolete("Has been moved to the individual services. Scheduled to be removed in Umbraco 18.")] + /// + /// Indicates whether to use the IFileSystemTreeService or the legacy implementation. + /// + /// + /// This is retained to ensure that any controllers outside of the CMS that use this base class with the obsolete constructor + /// continue to function until they can be updated to use the new service. + /// To be removed along with the constructor taking no parameters in Umbraco 19. + /// + private readonly bool _useFileSystemTreeService = true; + + [Obsolete("Has been moved to the individual services. Scheduled to be removed in Umbraco 19.")] protected abstract IFileSystem FileSystem { get; } [ActivatorUtilitiesConstructor] protected FileSystemTreeControllerBase(IFileSystemTreeService fileSystemTreeService) => _fileSystemTreeService = fileSystemTreeService; - [Obsolete("Use the other constructor. Scheduled for removal in Umbraco 18.")] - protected FileSystemTreeControllerBase() - : this(StaticServiceProvider.Instance.GetRequiredService()) - { - } + [Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 19.")] + protected FileSystemTreeControllerBase() => _useFileSystemTreeService = false; protected Task>> GetRoot(int skip, int take) { - FileSystemTreeItemPresentationModel[] viewModels = _fileSystemTreeService.GetPathViewModels(string.Empty, skip, take, out var totalItems); + FileSystemTreeItemPresentationModel[] viewModels = GetPathViewModels(string.Empty, skip, take, out var totalItems); PagedViewModel result = PagedViewModel(viewModels, totalItems); return Task.FromResult>>(Ok(result)); @@ -37,14 +43,14 @@ protected Task> protected Task>> GetChildren(string path, int skip, int take) { - FileSystemTreeItemPresentationModel[] viewModels = _fileSystemTreeService.GetPathViewModels(path, skip, take, out var totalItems); + FileSystemTreeItemPresentationModel[] viewModels = GetPathViewModels(path, skip, take, out var totalItems); PagedViewModel result = PagedViewModel(viewModels, totalItems); return Task.FromResult>>(Ok(result)); } /// - /// Gets the sibling of the targeted item based on its path. + /// Gets the siblings of the targeted item based on its path. /// /// The path to the item. /// The amount of siblings you want to fetch from before the items position in the array. @@ -61,17 +67,19 @@ protected Task protected virtual Task>> GetAncestors(string path, bool includeSelf = true) { path = path.VirtualPathToSystemPath(); - FileSystemTreeItemPresentationModel[] models = _fileSystemTreeService.GetAncestorModels(path, includeSelf); + FileSystemTreeItemPresentationModel[] models = GetAncestorModels(path, includeSelf); return Task.FromResult>>(Ok(models)); } - private PagedViewModel PagedViewModel(IEnumerable viewModels, long totalItems) - => new() { Total = totalItems, Items = viewModels }; - - [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")] + [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19.")] protected virtual FileSystemTreeItemPresentationModel[] GetAncestorModels(string path, bool includeSelf) { + if (_useFileSystemTreeService) + { + return _fileSystemTreeService.GetAncestorModels(path, includeSelf); + } + var directories = path.Split(Path.DirectorySeparatorChar).Take(Range.EndAt(Index.FromEnd(1))).ToArray(); var result = directories .Select((directory, index) => MapViewModel(string.Join(Path.DirectorySeparatorChar, directories.Take(index + 1)), directory, true)) @@ -86,28 +94,59 @@ protected virtual FileSystemTreeItemPresentationModel[] GetAncestorModels(string return result.ToArray(); } - [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")] + [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19.")] protected virtual string[] GetDirectories(string path) => FileSystem .GetDirectories(path) .OrderBy(directory => directory) .ToArray(); - [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")] + [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19.")] protected virtual string[] GetFiles(string path) => FileSystem .GetFiles(path) .OrderBy(file => file) .ToArray(); - [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")] + [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19.")] protected virtual bool DirectoryHasChildren(string path) => FileSystem.GetFiles(path).Any() || FileSystem.GetDirectories(path).Any(); - [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")] + [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19.")] private string GetFileSystemItemName(bool isFolder, string itemPath) => isFolder ? Path.GetFileName(itemPath) : FileSystem.GetFileName(itemPath); - [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")] + private FileSystemTreeItemPresentationModel[] GetPathViewModels(string path, int skip, int take, out long totalItems) + { + if (_useFileSystemTreeService) + { + return _fileSystemTreeService.GetPathViewModels(path, skip, take, out totalItems); + } + + path = path.VirtualPathToSystemPath(); + var allItems = GetDirectories(path) + .Select(directory => new { Path = directory, IsFolder = true }) + .Union(GetFiles(path).Select(file => new { Path = file, IsFolder = false })) + .ToArray(); + + totalItems = allItems.Length; + + FileSystemTreeItemPresentationModel ViewModel(string itemPath, bool isFolder) + => MapViewModel( + itemPath, + GetFileSystemItemName(isFolder, itemPath), + isFolder); + + return allItems + .Skip(skip) + .Take(take) + .Select(item => ViewModel(item.Path, item.IsFolder)) + .ToArray(); + } + + private PagedViewModel PagedViewModel(IEnumerable viewModels, long totalItems) + => new() { Total = totalItems, Items = viewModels }; + + [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19.")] private FileSystemTreeItemPresentationModel MapViewModel(string path, string name, bool isFolder) { var parentPath = Path.GetDirectoryName(path);