From 9733f1d7c566713d6aca8bd8da39d3b00ede1502 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 7 Oct 2024 13:32:57 +0200 Subject: [PATCH 1/5] Reintroduced a lot of extension methods as obsolete to avoid introducing breaking changes where possible --- .../Extensions/PublishedContentExtensions.cs | 551 ++++++++++++++++++ 1 file changed, 551 insertions(+) diff --git a/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs b/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs index 5139e23af964..d3ee2c1f2ea0 100644 --- a/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs +++ b/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs @@ -2,7 +2,9 @@ // See LICENSE for more details. using System.Data; +using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Core.Configuration.Models; +using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Membership; using Umbraco.Cms.Core.Models.PublishedContent; @@ -1898,5 +1900,554 @@ private static Dictionary GetAliasesAndNames(IContentTypeService private static Dictionary GetAliasesAndNames(IContentTypeBase? contentType) => contentType?.PropertyTypes.ToDictionary(x => x.Alias, x => x.Name) ?? new Dictionary(); + + #endregion + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IPublishedContent? Ancestor(this IPublishedContent content) + { + return content.Ancestor(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content)); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IPublishedContent? Ancestor(this IPublishedContent content, int maxLevel) + { + return content.Ancestor(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IPublishedContent? Ancestor(this IPublishedContent content, string contentTypeAlias) + { + return content.Ancestor(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), contentTypeAlias); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static T? Ancestor(this IPublishedContent content) + where T : class, IPublishedContent + { + return Ancestor(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content)); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static T? Ancestor(this IPublishedContent content, int maxLevel) + where T : class, IPublishedContent + { + return Ancestor(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Ancestors(this IPublishedContent content, int maxLevel) + { + return content.Ancestors(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Ancestors(this IPublishedContent content) + { + return content.Ancestors(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content)); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Ancestors(this IPublishedContent content, string contentTypeAlias) + { + return content.Ancestors(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), contentTypeAlias); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Ancestors(this IPublishedContent content) + where T : class, IPublishedContent + { + return Ancestors(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content)); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Ancestors(this IPublishedContent content, int maxLevel) + where T : class, IPublishedContent + { + return Ancestors(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IPublishedContent AncestorOrSelf(this IPublishedContent content, int maxLevel) + { + return AncestorOrSelf(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IPublishedContent AncestorOrSelf(this IPublishedContent content, string contentTypeAlias) + { + return AncestorOrSelf(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), contentTypeAlias); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static T? AncestorOrSelf(this IPublishedContent content, int maxLevel) + where T : class, IPublishedContent + { + return AncestorOrSelf(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static T? AncestorOrSelf(this IPublishedContent content) + where T : class, IPublishedContent + { + return AncestorOrSelf(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content)); + } + + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable AncestorsOrSelf(this IPublishedContent content, int maxLevel) + { + return content.AncestorsOrSelf(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable AncestorsOrSelf(this IPublishedContent content) + { + return content.AncestorsOrSelf(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content)); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable AncestorsOrSelf(this IPublishedContent content, string contentTypeAlias) + { + return content.Ancestors(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), contentTypeAlias); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable AncestorsOrSelf(this IPublishedContent content) + where T : class, IPublishedContent + { + return Ancestors(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content)); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable AncestorsOrSelf(this IPublishedContent content, int maxLevel) + where T : class, IPublishedContent + { + return AncestorsOrSelf(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); + } + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable AncestorsOrSelf(this IPublishedContent content, bool orSelf, + Func? func) + { + return AncestorsOrSelf(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), orSelf, func); + } + + [Obsolete( + "Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Breadcrumbs( + this IPublishedContent content, + bool andSelf = true) => + content.Breadcrumbs(StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), andSelf); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Breadcrumbs( + this IPublishedContent content, + int minLevel, + bool andSelf = true) => + content.Breadcrumbs(StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), minLevel, andSelf); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Breadcrumbs( + this IPublishedContent content, + bool andSelf = true) + where T : class, IPublishedContent=> + content.Breadcrumbs(StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), andSelf); + + + + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Children( + this IPublishedContent content, + IVariationContextAccessor? variationContextAccessor, + string? culture = null) + => Children(content, variationContextAccessor, + StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content),culture); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Children( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + Func predicate, + string? culture = null) => + content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), culture).Where(predicate); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable ChildrenOfType( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string? contentTypeAlias, + string? culture = null) => + content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), x => x.ContentType.Alias.InvariantEquals(contentTypeAlias), + culture); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Children( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string? culture = null) + where T : class, IPublishedContent => + content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), culture).OfType(); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static DataTable ChildrenAsTable( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + IContentTypeService contentTypeService, + IMediaTypeService mediaTypeService, + IMemberTypeService memberTypeService, + IPublishedUrlProvider publishedUrlProvider, + string contentTypeAliasFilter = "", + string? culture = null) + => GenerateDataTable(content, variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), contentTypeService, mediaTypeService, memberTypeService, publishedUrlProvider, contentTypeAliasFilter, culture); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable DescendantsOrSelfOfType( + this IEnumerable parentNodes, + IVariationContextAccessor variationContextAccessor, + string docTypeAlias, + string? culture = null) => parentNodes.SelectMany(x => + x.DescendantsOrSelfOfType(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(parentNodes.First()), docTypeAlias, culture)); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable DescendantsOrSelf( + this IEnumerable parentNodes, + IVariationContextAccessor variationContextAccessor, + string? culture = null) + where T : class, IPublishedContent => + parentNodes.SelectMany(x => x.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(parentNodes.First()), culture)); + + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Descendants( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string? culture = null) => + content.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), false, null, culture); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Descendants( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + int level, + string? culture = null) => + content.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), false, p => p.Level >= level, culture); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable DescendantsOfType( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string contentTypeAlias, string? culture = null) => + content.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), false, p => p.ContentType.Alias.InvariantEquals(contentTypeAlias), culture); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Descendants( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string? culture = null) + where T : class, IPublishedContent => + content.Descendants(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), culture).OfType(); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Descendants( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + int level, + string? culture = null) + where T : class, IPublishedContent => + content.Descendants(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), level, culture).OfType(); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable DescendantsOrSelf( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string? culture = null) => + content.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), true, null, culture); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable DescendantsOrSelf( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + int level, + string? culture = null) => + content.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), true, p => p.Level >= level, culture); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable DescendantsOrSelfOfType( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string contentTypeAlias, + string? culture = null) => + content.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), true, p => p.ContentType.Alias.InvariantEquals(contentTypeAlias), culture); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable DescendantsOrSelf( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string? culture = null) + where T : class, IPublishedContent => + content.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), culture).OfType(); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable DescendantsOrSelf( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + int level, + string? culture = null) + where T : class, IPublishedContent => + content.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), level, culture).OfType(); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IPublishedContent? Descendant( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string? culture = null) => + content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), culture)?.FirstOrDefault(); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IPublishedContent? Descendant( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + int level, + string? culture = null) => content + .EnumerateDescendants(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), false, culture).FirstOrDefault(x => x.Level == level); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IPublishedContent? DescendantOfType( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string contentTypeAlias, + string? culture = null) => content + .EnumerateDescendants(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), false, culture) + .FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias)); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static T? Descendant( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string? culture = null) + where T : class, IPublishedContent => + content.EnumerateDescendants(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), false, culture).FirstOrDefault(x => x is T) as T; + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static T? Descendant( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + int level, + string? culture = null) + where T : class, IPublishedContent => + content.Descendant(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), level, culture) as T; + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IPublishedContent? DescendantOrSelf( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + int level, + string? culture = null) => content + .EnumerateDescendants(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), true, culture).FirstOrDefault(x => x.Level == level); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IPublishedContent? DescendantOrSelfOfType( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string contentTypeAlias, + string? culture = null) => content + .EnumerateDescendants(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), true, culture) + .FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias)); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static T? DescendantOrSelf( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string? culture = null) + where T : class, IPublishedContent => + content.EnumerateDescendants(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), true, culture).FirstOrDefault(x => x is T) as T; + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static T? DescendantOrSelf( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + int level, + string? culture = null) + where T : class, IPublishedContent => + content.DescendantOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), level, culture) as T; + + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IPublishedContent? FirstChild( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string? culture = null) => + content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), culture)?.FirstOrDefault(); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IPublishedContent? FirstChildOfType( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string contentTypeAlias, + string? culture = null) => + content.ChildrenOfType(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), contentTypeAlias, culture)?.FirstOrDefault(); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IPublishedContent? FirstChild( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + Func predicate, + string? culture = null) + => content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), predicate, culture)?.FirstOrDefault(); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IPublishedContent? FirstChild( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + Guid uniqueId, + string? culture = null) => content + .Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), x => x.Key == uniqueId, culture)?.FirstOrDefault(); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static T? FirstChild( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string? culture = null) + where T : class, IPublishedContent => + content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), culture)?.FirstOrDefault(); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static T? FirstChild( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + Func predicate, + string? culture = null) + where T : class, IPublishedContent => + content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), culture)?.FirstOrDefault(predicate); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static T? Parent( + this IPublishedContent content) + where T : class, IPublishedContent => + content.GetParent(StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content)) as T; + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IPublishedContent Root( + this IPublishedContent content) => content.AncestorOrSelf(StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), 1); + + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static T? Root( + this IPublishedContent content) + where T : class, IPublishedContent => + content.AncestorOrSelf(StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), 1); + + [Obsolete( + "Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Siblings( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string? culture = null) => + Siblings(content, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), variationContextAccessor, culture); + + [Obsolete( + "Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable SiblingsOfType( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string contentTypeAlias, + string? culture = null) => + SiblingsOfType(content, variationContextAccessor, + StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), contentTypeAlias, culture); + + [Obsolete( + "Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable Siblings( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string? culture = null) + where T : class, IPublishedContent => + Siblings(content, variationContextAccessor, + StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), culture); + + [Obsolete( + "Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable? SiblingsAndSelf( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string? culture = null) => SiblingsAndSelf(content, + StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), variationContextAccessor, culture); + + [Obsolete( + "Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable SiblingsAndSelfOfType( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string contentTypeAlias, + string? culture = null) => SiblingsAndSelfOfType(content, variationContextAccessor, + StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), contentTypeAlias, culture); + + [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + public static IEnumerable SiblingsAndSelf( + this IPublishedContent content, + IVariationContextAccessor variationContextAccessor, + string? culture = null) + where T : class, IPublishedContent => SiblingsAndSelf(content, variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + GetNavigationQueryService(content), culture); + + + private static INavigationQueryService GetNavigationQueryService(IPublishedContent content) + { + switch (content.ContentType.ItemType) + { + case PublishedItemType.Content: + return StaticServiceProvider.Instance.GetRequiredService(); + case PublishedItemType.Media: + return StaticServiceProvider.Instance.GetRequiredService(); + default: + throw new NotSupportedException("Unsupported content type."); + } + + } } From eed6c26e0bc22146054cc22102653b7f5ff72a35 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 8 Oct 2024 09:34:00 +0200 Subject: [PATCH 2/5] Missing commit --- .../FriendlyPublishedContentExtensions.cs | 111 ++++++++++-------- 1 file changed, 64 insertions(+), 47 deletions(-) diff --git a/src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs b/src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs index 858c7d82cdea..40e869495d9c 100644 --- a/src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs @@ -25,6 +25,9 @@ public static class FriendlyPublishedContentExtensions private static IDocumentNavigationQueryService DocumentNavigationQueryService { get; } = StaticServiceProvider.Instance.GetRequiredService(); + private static IMediaNavigationQueryService MediaNavigationQueryService { get; } = + StaticServiceProvider.Instance.GetRequiredService(); + private static IPublishedModelFactory PublishedModelFactory { get; } = StaticServiceProvider.Instance.GetRequiredService(); @@ -61,6 +64,19 @@ public static class FriendlyPublishedContentExtensions private static IMemberTypeService MemberTypeService { get; } = StaticServiceProvider.Instance.GetRequiredService(); + private static INavigationQueryService GetNavigationQueryService(IPublishedContent content) + { + switch (content.ContentType.ItemType) + { + case PublishedItemType.Content: + return DocumentNavigationQueryService; + case PublishedItemType.Media: + return MediaNavigationQueryService; + default: + throw new NotSupportedException("Unsupported content type."); + } + + } /// /// Creates a strongly typed published content model for an internal published content. /// @@ -207,7 +223,7 @@ public static bool HasValue( /// set to 1. /// public static IPublishedContent Root(this IPublishedContent content) - => content.Root(PublishedContentCache, DocumentNavigationQueryService); + => content.Root(PublishedContentCache, GetNavigationQueryService(content)); /// /// Gets the root content (ancestor or self at level 1) for the specified if it's of the @@ -226,7 +242,7 @@ public static IPublishedContent Root(this IPublishedContent content) /// public static T? Root(this IPublishedContent content) where T : class, IPublishedContent - => content.Root(PublishedContentCache, DocumentNavigationQueryService); + => content.Root(PublishedContentCache, GetNavigationQueryService(content)); /// /// Gets the parent of the content item. @@ -236,7 +252,7 @@ public static IPublishedContent Root(this IPublishedContent content) /// The parent of content of the specified content type or null. public static T? Parent(this IPublishedContent content) where T : class, IPublishedContent - => content.Parent(PublishedContentCache, DocumentNavigationQueryService); + => content.Parent(PublishedContentCache, GetNavigationQueryService(content)); /// /// Gets the ancestors of the content. @@ -245,7 +261,7 @@ public static IPublishedContent Root(this IPublishedContent content) /// The ancestors of the content, in down-top order. /// Does not consider the content itself. public static IEnumerable Ancestors(this IPublishedContent content) - => content.Ancestors(PublishedContentCache, DocumentNavigationQueryService); + => content.Ancestors(PublishedContentCache, GetNavigationQueryService(content)); /// /// Gets the content and its ancestors. @@ -253,7 +269,7 @@ public static IEnumerable Ancestors(this IPublishedContent co /// The content. /// The content and its ancestors, in down-top order. public static IEnumerable AncestorsOrSelf(this IPublishedContent content) - => content.AncestorsOrSelf(PublishedContentCache, DocumentNavigationQueryService); + => content.AncestorsOrSelf(PublishedContentCache, GetNavigationQueryService(content)); /// /// Gets the content and its ancestors, of a specified content type. @@ -264,7 +280,7 @@ public static IEnumerable AncestorsOrSelf(this IPublishedCont /// May or may not begin with the content itself, depending on its content type. public static IEnumerable AncestorsOrSelf(this IPublishedContent content) where T : class, IPublishedContent - => content.AncestorsOrSelf(PublishedContentCache, DocumentNavigationQueryService); + => content.AncestorsOrSelf(PublishedContentCache, GetNavigationQueryService(content)); /// /// Gets the ancestor of the content, i.e. its parent. @@ -272,7 +288,7 @@ public static IEnumerable AncestorsOrSelf(this IPublishedContent content) /// The content. /// The ancestor of the content. public static IPublishedContent? Ancestor(this IPublishedContent content) - => content.Ancestor(PublishedContentCache, DocumentNavigationQueryService); + => content.Ancestor(PublishedContentCache, GetNavigationQueryService(content)); /// /// Gets the nearest ancestor of the content, of a specified content type. @@ -283,7 +299,7 @@ public static IEnumerable AncestorsOrSelf(this IPublishedContent content) /// Does not consider the content itself. May return null. public static T? Ancestor(this IPublishedContent content) where T : class, IPublishedContent - => content.Ancestor(PublishedContentCache, DocumentNavigationQueryService); + => content.Ancestor(PublishedContentCache, GetNavigationQueryService(content)); /// /// Gets the content or its nearest ancestor, of a specified content type. @@ -294,7 +310,7 @@ public static IEnumerable AncestorsOrSelf(this IPublishedContent content) /// May or may not return the content itself depending on its content type. May return null. public static T? AncestorOrSelf(this IPublishedContent content) where T : class, IPublishedContent - => content.AncestorOrSelf(PublishedContentCache, DocumentNavigationQueryService); + => content.AncestorOrSelf(PublishedContentCache, GetNavigationQueryService(content)); /// /// Returns all DescendantsOrSelf of all content referenced @@ -311,7 +327,7 @@ public static IEnumerable AncestorsOrSelf(this IPublishedContent content) /// public static IEnumerable DescendantsOrSelfOfType( this IEnumerable parentNodes, string docTypeAlias, string? culture = null) - => parentNodes.DescendantsOrSelfOfType(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, docTypeAlias, culture); + => parentNodes.DescendantsOrSelfOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(parentNodes.First()), docTypeAlias, culture); /// /// Returns all DescendantsOrSelf of all content referenced @@ -329,77 +345,77 @@ public static IEnumerable DescendantsOrSelf( this IEnumerable parentNodes, string? culture = null) where T : class, IPublishedContent - => parentNodes.DescendantsOrSelf(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, culture); + => parentNodes.DescendantsOrSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(parentNodes.First()), culture); public static IEnumerable Descendants(this IPublishedContent content, string? culture = null) - => content.Descendants(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, culture); + => content.Descendants(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); public static IEnumerable Descendants(this IPublishedContent content, int level, string? culture = null) - => content.Descendants(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, level, culture); + => content.Descendants(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), level, culture); public static IEnumerable DescendantsOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) - => content.DescendantsOfType(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, contentTypeAlias, culture); + => content.DescendantsOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), contentTypeAlias, culture); public static IEnumerable Descendants(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent - => content.Descendants(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, culture); + => content.Descendants(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); public static IEnumerable Descendants(this IPublishedContent content, int level, string? culture = null) where T : class, IPublishedContent - => content.Descendants(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, level, culture); + => content.Descendants(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), level, culture); public static IEnumerable DescendantsOrSelf( this IPublishedContent content, string? culture = null) - => content.DescendantsOrSelf(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, culture); + => content.DescendantsOrSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); public static IEnumerable DescendantsOrSelf(this IPublishedContent content, int level, string? culture = null) - => content.DescendantsOrSelf(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, level, culture); + => content.DescendantsOrSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), level, culture); public static IEnumerable DescendantsOrSelfOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) - => content.DescendantsOrSelfOfType(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, contentTypeAlias, culture); + => content.DescendantsOrSelfOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), contentTypeAlias, culture); public static IEnumerable DescendantsOrSelf(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent - => content.DescendantsOrSelf(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, culture); + => content.DescendantsOrSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); public static IEnumerable DescendantsOrSelf(this IPublishedContent content, int level, string? culture = null) where T : class, IPublishedContent - => content.DescendantsOrSelf(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, level, culture); + => content.DescendantsOrSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), level, culture); public static IPublishedContent? Descendant(this IPublishedContent content, string? culture = null) - => content.Descendant(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, culture); + => content.Descendant(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); public static IPublishedContent? Descendant(this IPublishedContent content, int level, string? culture = null) - => content.Descendant(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, level, culture); + => content.Descendant(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), level, culture); public static IPublishedContent? DescendantOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) - => content.DescendantOfType(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, contentTypeAlias, culture); + => content.DescendantOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), contentTypeAlias, culture); public static T? Descendant(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent - => content.Descendant(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, culture); + => content.Descendant(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); public static T? Descendant(this IPublishedContent content, int level, string? culture = null) where T : class, IPublishedContent - => content.Descendant(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, level, culture); + => content.Descendant(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), level, culture); public static IPublishedContent DescendantOrSelf(this IPublishedContent content, string? culture = null) => content.DescendantOrSelf(VariationContextAccessor, culture); public static IPublishedContent? DescendantOrSelf(this IPublishedContent content, int level, string? culture = null) - => content.DescendantOrSelf(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, level, culture); + => content.DescendantOrSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), level, culture); public static IPublishedContent? DescendantOrSelfOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) - => content.DescendantOrSelfOfType(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, contentTypeAlias, culture); + => content.DescendantOrSelfOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), contentTypeAlias, culture); public static T? DescendantOrSelf(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent - => content.DescendantOrSelf(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, culture); + => content.DescendantOrSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); public static T? DescendantOrSelf(this IPublishedContent content, int level, string? culture = null) where T : class, IPublishedContent - => content.DescendantOrSelf(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, level, culture); + => content.DescendantOrSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), level, culture); /// /// Gets the children of the content item. @@ -427,7 +443,7 @@ public static IPublishedContent DescendantOrSelf(this IPublishedContent content, /// /// public static IEnumerable Children(this IPublishedContent content, string? culture = null) - => content.Children(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, culture); + => content.Children(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); /// /// Gets the children of the content, filtered by a predicate. @@ -446,7 +462,7 @@ public static IEnumerable Children(this IPublishedContent con this IPublishedContent content, Func predicate, string? culture = null) - => content.Children(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, predicate, culture); + => content.Children(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), predicate, culture); /// /// Gets the children of the content, of any of the specified types. @@ -459,7 +475,7 @@ public static IEnumerable Children(this IPublishedContent con /// The content type alias. /// The children of the content, of any of the specified types. public static IEnumerable? ChildrenOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) - => content.ChildrenOfType(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, contentTypeAlias, culture); + => content.ChildrenOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), contentTypeAlias, culture); /// /// Gets the children of the content, of a given content type. @@ -476,30 +492,30 @@ public static IEnumerable Children(this IPublishedContent con /// public static IEnumerable? Children(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent - => content.Children(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, culture); + => content.Children(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); public static IPublishedContent? FirstChild(this IPublishedContent content, string? culture = null) - => content.FirstChild(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, culture); + => content.FirstChild(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); /// /// Gets the first child of the content, of a given content type. /// public static IPublishedContent? FirstChildOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) - => content.FirstChildOfType(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, contentTypeAlias, culture); + => content.FirstChildOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), contentTypeAlias, culture); public static IPublishedContent? FirstChild(this IPublishedContent content, Func predicate, string? culture = null) - => content.FirstChild(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, predicate, culture); + => content.FirstChild(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), predicate, culture); public static IPublishedContent? FirstChild(this IPublishedContent content, Guid uniqueId, string? culture = null) - => content.FirstChild(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, uniqueId, culture); + => content.FirstChild(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), uniqueId, culture); public static T? FirstChild(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent - => content.FirstChild(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, culture); + => content.FirstChild(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); public static T? FirstChild(this IPublishedContent content, Func predicate, string? culture = null) where T : class, IPublishedContent - => content.FirstChild(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, predicate, culture); + => content.FirstChild(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), predicate, culture); /// /// Gets the siblings of the content. @@ -514,7 +530,7 @@ public static IEnumerable Children(this IPublishedContent con /// Note that in V7 this method also return the content node self. /// public static IEnumerable? Siblings(this IPublishedContent content, string? culture = null) - => content.Siblings(PublishedContentCache, DocumentNavigationQueryService, VariationContextAccessor, culture); + => content.Siblings(PublishedContentCache, GetNavigationQueryService(content), VariationContextAccessor, culture); /// /// Gets the siblings of the content, of a given content type. @@ -530,7 +546,7 @@ public static IEnumerable Children(this IPublishedContent con /// Note that in V7 this method also return the content node self. /// public static IEnumerable? SiblingsOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) - => content.SiblingsOfType(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, contentTypeAlias, culture); + => content.SiblingsOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), contentTypeAlias, culture); /// /// Gets the siblings of the content, of a given content type. @@ -547,7 +563,7 @@ public static IEnumerable Children(this IPublishedContent con /// public static IEnumerable? Siblings(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent - => content.Siblings(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, culture); + => content.Siblings(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); /// /// Gets the siblings of the content including the node itself to indicate the position. @@ -561,7 +577,7 @@ public static IEnumerable Children(this IPublishedContent con public static IEnumerable? SiblingsAndSelf( this IPublishedContent content, string? culture = null) - => content.SiblingsAndSelf(PublishedContentCache, DocumentNavigationQueryService, VariationContextAccessor, culture); + => content.SiblingsAndSelf(PublishedContentCache, GetNavigationQueryService(content), VariationContextAccessor, culture); /// /// Gets the siblings of the content including the node itself to indicate the position, of a given content type. @@ -577,7 +593,7 @@ public static IEnumerable Children(this IPublishedContent con this IPublishedContent content, string contentTypeAlias, string? culture = null) - => content.SiblingsAndSelfOfType(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, contentTypeAlias, culture); + => content.SiblingsAndSelfOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), contentTypeAlias, culture); /// /// Gets the siblings of the content including the node itself to indicate the position, of a given content type. @@ -591,7 +607,7 @@ public static IEnumerable Children(this IPublishedContent con /// The siblings of the content including the node itself, of the given content type. public static IEnumerable? SiblingsAndSelf(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent - => content.SiblingsAndSelf(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, culture); + => content.SiblingsAndSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); /// /// Gets the url of the content item. @@ -627,7 +643,7 @@ public static DataTable ChildrenAsTable(this IPublishedContent content, string c content.ChildrenAsTable( VariationContextAccessor, PublishedContentCache, - DocumentNavigationQueryService, + GetNavigationQueryService(content), ContentTypeService, MediaTypeService, MemberTypeService, @@ -700,4 +716,5 @@ public static IEnumerable SearchChildren( string term, string? indexName = null) => content.SearchChildren(ExamineManager, UmbracoContextAccessor, term, indexName); + } From dea26bc7abb4d863634bcd8d4502c868601f585e Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 8 Oct 2024 10:25:56 +0200 Subject: [PATCH 3/5] Removed ambiguous methods --- .../Extensions/PublishedContentExtensions.cs | 64 ++----------------- 1 file changed, 5 insertions(+), 59 deletions(-) diff --git a/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs b/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs index d3ee2c1f2ea0..83d3da64f4d6 100644 --- a/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs +++ b/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs @@ -1904,11 +1904,11 @@ private static Dictionary GetAliasesAndNames(IContentTypeBase? c #endregion - [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] - public static IPublishedContent? Ancestor(this IPublishedContent content) - { - return content.Ancestor(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content)); - } + // [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] + // public static IPublishedContent? Ancestor(this IPublishedContent content) + // { + // return content.Ancestor(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content)); + // } [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IPublishedContent? Ancestor(this IPublishedContent content, int maxLevel) @@ -1922,13 +1922,6 @@ private static Dictionary GetAliasesAndNames(IContentTypeBase? c return content.Ancestor(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), contentTypeAlias); } - [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] - public static T? Ancestor(this IPublishedContent content) - where T : class, IPublishedContent - { - return Ancestor(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content)); - } - [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static T? Ancestor(this IPublishedContent content, int maxLevel) where T : class, IPublishedContent @@ -1942,12 +1935,6 @@ public static IEnumerable Ancestors(this IPublishedContent co return content.Ancestors(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); } - [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] - public static IEnumerable Ancestors(this IPublishedContent content) - { - return content.Ancestors(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content)); - } - [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable Ancestors(this IPublishedContent content, string contentTypeAlias) { @@ -1987,39 +1974,18 @@ public static IPublishedContent AncestorOrSelf(this IPublishedContent content, s return AncestorOrSelf(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); } - [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] - public static T? AncestorOrSelf(this IPublishedContent content) - where T : class, IPublishedContent - { - return AncestorOrSelf(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content)); - } - - [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable AncestorsOrSelf(this IPublishedContent content, int maxLevel) { return content.AncestorsOrSelf(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); } - [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] - public static IEnumerable AncestorsOrSelf(this IPublishedContent content) - { - return content.AncestorsOrSelf(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content)); - } - [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable AncestorsOrSelf(this IPublishedContent content, string contentTypeAlias) { return content.Ancestors(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), contentTypeAlias); } - [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] - public static IEnumerable AncestorsOrSelf(this IPublishedContent content) - where T : class, IPublishedContent - { - return Ancestors(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content)); - } - [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable AncestorsOrSelf(this IPublishedContent content, int maxLevel) where T : class, IPublishedContent @@ -2358,26 +2324,6 @@ public static IEnumerable DescendantsOrSelf( content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), culture)?.FirstOrDefault(predicate); - [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] - public static T? Parent( - this IPublishedContent content) - where T : class, IPublishedContent => - content.GetParent(StaticServiceProvider.Instance.GetRequiredService(), - GetNavigationQueryService(content)) as T; - - [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] - public static IPublishedContent Root( - this IPublishedContent content) => content.AncestorOrSelf(StaticServiceProvider.Instance.GetRequiredService(), - GetNavigationQueryService(content), 1); - - - [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] - public static T? Root( - this IPublishedContent content) - where T : class, IPublishedContent => - content.AncestorOrSelf(StaticServiceProvider.Instance.GetRequiredService(), - GetNavigationQueryService(content), 1); - [Obsolete( "Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable Siblings( From 02befd185482e6f45ac8839fb191c9f86aa4df45 Mon Sep 17 00:00:00 2001 From: nikolajlauridsen Date: Tue, 8 Oct 2024 13:24:28 +0200 Subject: [PATCH 4/5] Fixup cache injection --- .../Extensions/PublishedContentExtensions.cs | 145 ++++++++---------- 1 file changed, 68 insertions(+), 77 deletions(-) diff --git a/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs b/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs index 83d3da64f4d6..2c110496f03d 100644 --- a/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs +++ b/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs @@ -1904,100 +1904,94 @@ private static Dictionary GetAliasesAndNames(IContentTypeBase? c #endregion - // [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] - // public static IPublishedContent? Ancestor(this IPublishedContent content) - // { - // return content.Ancestor(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content)); - // } - [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IPublishedContent? Ancestor(this IPublishedContent content, int maxLevel) { - return content.Ancestor(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); + return content.Ancestor(GetPublishedCache(content), GetNavigationQueryService(content), maxLevel); } [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IPublishedContent? Ancestor(this IPublishedContent content, string contentTypeAlias) { - return content.Ancestor(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), contentTypeAlias); + return content.Ancestor(GetPublishedCache(content), GetNavigationQueryService(content), contentTypeAlias); } [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static T? Ancestor(this IPublishedContent content, int maxLevel) where T : class, IPublishedContent { - return Ancestor(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); + return Ancestor(content, GetPublishedCache(content), GetNavigationQueryService(content), maxLevel); } [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable Ancestors(this IPublishedContent content, int maxLevel) { - return content.Ancestors(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); + return content.Ancestors(GetPublishedCache(content), GetNavigationQueryService(content), maxLevel); } [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable Ancestors(this IPublishedContent content, string contentTypeAlias) { - return content.Ancestors(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), contentTypeAlias); + return content.Ancestors(GetPublishedCache(content), GetNavigationQueryService(content), contentTypeAlias); } [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable Ancestors(this IPublishedContent content) where T : class, IPublishedContent { - return Ancestors(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content)); + return Ancestors(content, GetPublishedCache(content), GetNavigationQueryService(content)); } [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable Ancestors(this IPublishedContent content, int maxLevel) where T : class, IPublishedContent { - return Ancestors(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); + return Ancestors(content, GetPublishedCache(content), GetNavigationQueryService(content), maxLevel); } [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IPublishedContent AncestorOrSelf(this IPublishedContent content, int maxLevel) { - return AncestorOrSelf(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); + return AncestorOrSelf(content, GetPublishedCache(content), GetNavigationQueryService(content), maxLevel); } [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IPublishedContent AncestorOrSelf(this IPublishedContent content, string contentTypeAlias) { - return AncestorOrSelf(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), contentTypeAlias); + return AncestorOrSelf(content, GetPublishedCache(content), GetNavigationQueryService(content), contentTypeAlias); } [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static T? AncestorOrSelf(this IPublishedContent content, int maxLevel) where T : class, IPublishedContent { - return AncestorOrSelf(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); + return AncestorOrSelf(content, GetPublishedCache(content), GetNavigationQueryService(content), maxLevel); } [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable AncestorsOrSelf(this IPublishedContent content, int maxLevel) { - return content.AncestorsOrSelf(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); + return content.AncestorsOrSelf(GetPublishedCache(content), GetNavigationQueryService(content), maxLevel); } [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable AncestorsOrSelf(this IPublishedContent content, string contentTypeAlias) { - return content.Ancestors(StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), contentTypeAlias); + return content.Ancestors(GetPublishedCache(content), GetNavigationQueryService(content), contentTypeAlias); } [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable AncestorsOrSelf(this IPublishedContent content, int maxLevel) where T : class, IPublishedContent { - return AncestorsOrSelf(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), maxLevel); + return AncestorsOrSelf(content, GetPublishedCache(content), GetNavigationQueryService(content), maxLevel); } [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable AncestorsOrSelf(this IPublishedContent content, bool orSelf, Func? func) { - return AncestorsOrSelf(content, StaticServiceProvider.Instance.GetRequiredService(), GetNavigationQueryService(content), orSelf, func); + return AncestorsOrSelf(content, GetPublishedCache(content), GetNavigationQueryService(content), orSelf, func); } [Obsolete( @@ -2005,36 +1999,28 @@ public static IEnumerable AncestorsOrSelf(this IPublishedCont public static IEnumerable Breadcrumbs( this IPublishedContent content, bool andSelf = true) => - content.Breadcrumbs(StaticServiceProvider.Instance.GetRequiredService(), - GetNavigationQueryService(content), andSelf); + content.Breadcrumbs(GetPublishedCache(content), GetNavigationQueryService(content), andSelf); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable Breadcrumbs( this IPublishedContent content, int minLevel, bool andSelf = true) => - content.Breadcrumbs(StaticServiceProvider.Instance.GetRequiredService(), - GetNavigationQueryService(content), minLevel, andSelf); + content.Breadcrumbs(GetPublishedCache(content), GetNavigationQueryService(content), minLevel, andSelf); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable Breadcrumbs( this IPublishedContent content, bool andSelf = true) where T : class, IPublishedContent=> - content.Breadcrumbs(StaticServiceProvider.Instance.GetRequiredService(), - GetNavigationQueryService(content), andSelf); - - - + content.Breadcrumbs(GetPublishedCache(content), GetNavigationQueryService(content), andSelf); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable Children( this IPublishedContent content, IVariationContextAccessor? variationContextAccessor, string? culture = null) - => Children(content, variationContextAccessor, - StaticServiceProvider.Instance.GetRequiredService(), - GetNavigationQueryService(content),culture); + => Children(content, variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable Children( @@ -2042,8 +2028,7 @@ public static IEnumerable Children( IVariationContextAccessor variationContextAccessor, Func predicate, string? culture = null) => - content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), - GetNavigationQueryService(content), culture).Where(predicate); + content.Children(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture).Where(predicate); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable ChildrenOfType( @@ -2051,7 +2036,7 @@ public static IEnumerable ChildrenOfType( IVariationContextAccessor variationContextAccessor, string? contentTypeAlias, string? culture = null) => - content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.Children(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), x => x.ContentType.Alias.InvariantEquals(contentTypeAlias), culture); @@ -2061,7 +2046,7 @@ public static IEnumerable Children( IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent => - content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.Children(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture).OfType(); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2074,7 +2059,7 @@ public static DataTable ChildrenAsTable( IPublishedUrlProvider publishedUrlProvider, string contentTypeAliasFilter = "", string? culture = null) - => GenerateDataTable(content, variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + => GenerateDataTable(content, variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), contentTypeService, mediaTypeService, memberTypeService, publishedUrlProvider, contentTypeAliasFilter, culture); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2083,7 +2068,7 @@ public static IEnumerable DescendantsOrSelfOfType( IVariationContextAccessor variationContextAccessor, string docTypeAlias, string? culture = null) => parentNodes.SelectMany(x => - x.DescendantsOrSelfOfType(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + x.DescendantsOrSelfOfType(variationContextAccessor, GetPublishedCache(parentNodes.First()), GetNavigationQueryService(parentNodes.First()), docTypeAlias, culture)); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2092,7 +2077,7 @@ public static IEnumerable DescendantsOrSelf( IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent => - parentNodes.SelectMany(x => x.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + parentNodes.SelectMany(x => x.DescendantsOrSelf(variationContextAccessor, GetPublishedCache(parentNodes.First()), GetNavigationQueryService(parentNodes.First()), culture)); @@ -2101,7 +2086,7 @@ public static IEnumerable Descendants( this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) => - content.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.DescendantsOrSelf(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), false, null, culture); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2110,7 +2095,7 @@ public static IEnumerable Descendants( IVariationContextAccessor variationContextAccessor, int level, string? culture = null) => - content.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.DescendantsOrSelf(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), false, p => p.Level >= level, culture); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2118,7 +2103,7 @@ public static IEnumerable DescendantsOfType( this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string? culture = null) => - content.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.DescendantsOrSelf(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), false, p => p.ContentType.Alias.InvariantEquals(contentTypeAlias), culture); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2127,7 +2112,7 @@ public static IEnumerable Descendants( IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent => - content.Descendants(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.Descendants(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture).OfType(); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2137,7 +2122,7 @@ public static IEnumerable Descendants( int level, string? culture = null) where T : class, IPublishedContent => - content.Descendants(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.Descendants(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), level, culture).OfType(); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2145,7 +2130,7 @@ public static IEnumerable DescendantsOrSelf( this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) => - content.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.DescendantsOrSelf(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), true, null, culture); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2154,7 +2139,7 @@ public static IEnumerable DescendantsOrSelf( IVariationContextAccessor variationContextAccessor, int level, string? culture = null) => - content.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.DescendantsOrSelf(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), true, p => p.Level >= level, culture); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2163,7 +2148,7 @@ public static IEnumerable DescendantsOrSelfOfType( IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string? culture = null) => - content.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.DescendantsOrSelf(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), true, p => p.ContentType.Alias.InvariantEquals(contentTypeAlias), culture); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2172,7 +2157,7 @@ public static IEnumerable DescendantsOrSelf( IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent => - content.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.DescendantsOrSelf(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture).OfType(); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2182,7 +2167,7 @@ public static IEnumerable DescendantsOrSelf( int level, string? culture = null) where T : class, IPublishedContent => - content.DescendantsOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.DescendantsOrSelf(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), level, culture).OfType(); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2190,7 +2175,7 @@ public static IEnumerable DescendantsOrSelf( this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) => - content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.Children(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture)?.FirstOrDefault(); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2199,7 +2184,7 @@ public static IEnumerable DescendantsOrSelf( IVariationContextAccessor variationContextAccessor, int level, string? culture = null) => content - .EnumerateDescendants(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + .EnumerateDescendants(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), false, culture).FirstOrDefault(x => x.Level == level); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2208,7 +2193,7 @@ public static IEnumerable DescendantsOrSelf( IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string? culture = null) => content - .EnumerateDescendants(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + .EnumerateDescendants(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), false, culture) .FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias)); @@ -2218,7 +2203,7 @@ public static IEnumerable DescendantsOrSelf( IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent => - content.EnumerateDescendants(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.EnumerateDescendants(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), false, culture).FirstOrDefault(x => x is T) as T; [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2228,7 +2213,7 @@ public static IEnumerable DescendantsOrSelf( int level, string? culture = null) where T : class, IPublishedContent => - content.Descendant(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.Descendant(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), level, culture) as T; [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2237,7 +2222,7 @@ public static IEnumerable DescendantsOrSelf( IVariationContextAccessor variationContextAccessor, int level, string? culture = null) => content - .EnumerateDescendants(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + .EnumerateDescendants(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), true, culture).FirstOrDefault(x => x.Level == level); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2246,7 +2231,7 @@ public static IEnumerable DescendantsOrSelf( IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string? culture = null) => content - .EnumerateDescendants(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + .EnumerateDescendants(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), true, culture) .FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias)); @@ -2256,7 +2241,7 @@ public static IEnumerable DescendantsOrSelf( IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent => - content.EnumerateDescendants(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.EnumerateDescendants(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), true, culture).FirstOrDefault(x => x is T) as T; [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2266,7 +2251,7 @@ public static IEnumerable DescendantsOrSelf( int level, string? culture = null) where T : class, IPublishedContent => - content.DescendantOrSelf(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.DescendantOrSelf(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), level, culture) as T; @@ -2275,7 +2260,7 @@ public static IEnumerable DescendantsOrSelf( this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) => - content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.Children(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture)?.FirstOrDefault(); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2284,7 +2269,7 @@ public static IEnumerable DescendantsOrSelf( IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string? culture = null) => - content.ChildrenOfType(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.ChildrenOfType(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), contentTypeAlias, culture)?.FirstOrDefault(); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2293,7 +2278,7 @@ public static IEnumerable DescendantsOrSelf( IVariationContextAccessor variationContextAccessor, Func predicate, string? culture = null) - => content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + => content.Children(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), predicate, culture)?.FirstOrDefault(); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2302,7 +2287,7 @@ public static IEnumerable DescendantsOrSelf( IVariationContextAccessor variationContextAccessor, Guid uniqueId, string? culture = null) => content - .Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + .Children(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), x => x.Key == uniqueId, culture)?.FirstOrDefault(); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2311,7 +2296,7 @@ public static IEnumerable DescendantsOrSelf( IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent => - content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.Children(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture)?.FirstOrDefault(); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2321,7 +2306,7 @@ public static IEnumerable DescendantsOrSelf( Func predicate, string? culture = null) where T : class, IPublishedContent => - content.Children(variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + content.Children(variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture)?.FirstOrDefault(predicate); [Obsolete( @@ -2330,8 +2315,7 @@ public static IEnumerable Siblings( this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) => - Siblings(content, StaticServiceProvider.Instance.GetRequiredService(), - GetNavigationQueryService(content), variationContextAccessor, culture); + Siblings(content, GetPublishedCache(content), GetNavigationQueryService(content), variationContextAccessor, culture); [Obsolete( "Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2341,8 +2325,7 @@ public static IEnumerable SiblingsOfType( string contentTypeAlias, string? culture = null) => SiblingsOfType(content, variationContextAccessor, - StaticServiceProvider.Instance.GetRequiredService(), - GetNavigationQueryService(content), contentTypeAlias, culture); + GetPublishedCache(content), GetNavigationQueryService(content), contentTypeAlias, culture); [Obsolete( "Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2351,18 +2334,14 @@ public static IEnumerable Siblings( IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent => - Siblings(content, variationContextAccessor, - StaticServiceProvider.Instance.GetRequiredService(), - GetNavigationQueryService(content), culture); + Siblings(content, variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture); [Obsolete( "Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] public static IEnumerable? SiblingsAndSelf( this IPublishedContent content, IVariationContextAccessor variationContextAccessor, - string? culture = null) => SiblingsAndSelf(content, - StaticServiceProvider.Instance.GetRequiredService(), - GetNavigationQueryService(content), variationContextAccessor, culture); + string? culture = null) => SiblingsAndSelf(content, GetPublishedCache(content), GetNavigationQueryService(content), variationContextAccessor, culture); [Obsolete( "Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2370,8 +2349,7 @@ public static IEnumerable SiblingsAndSelfOfType( this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, - string? culture = null) => SiblingsAndSelfOfType(content, variationContextAccessor, - StaticServiceProvider.Instance.GetRequiredService(), + string? culture = null) => SiblingsAndSelfOfType(content, variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), contentTypeAlias, culture); [Obsolete("Please use IPublishedCache and IDocumentNavigationQueryService or IMediaNavigationQueryService directly. This will be removed in a future version of Umbraco")] @@ -2379,7 +2357,7 @@ public static IEnumerable SiblingsAndSelf( this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) - where T : class, IPublishedContent => SiblingsAndSelf(content, variationContextAccessor, StaticServiceProvider.Instance.GetRequiredService(), + where T : class, IPublishedContent => SiblingsAndSelf(content, variationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture); @@ -2396,4 +2374,17 @@ private static INavigationQueryService GetNavigationQueryService(IPublishedConte } } + + private static IPublishedCache GetPublishedCache(IPublishedContent content) + { + switch (content.ContentType.ItemType) + { + case PublishedItemType.Content: + return StaticServiceProvider.Instance.GetRequiredService(); + case PublishedItemType.Media: + return StaticServiceProvider.Instance.GetRequiredService(); + default: + throw new NotSupportedException("Unsupported content type."); + } + } } From 1f40cb145b6ea060ba8658cc98a583058508e8ae Mon Sep 17 00:00:00 2001 From: nikolajlauridsen Date: Tue, 8 Oct 2024 13:38:47 +0200 Subject: [PATCH 5/5] Return the correct cache in FriendlyPublishedContentExtensions --- .../FriendlyPublishedContentExtensions.cs | 111 ++++++++++-------- 1 file changed, 64 insertions(+), 47 deletions(-) diff --git a/src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs b/src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs index 40e869495d9c..60c7a27a57eb 100644 --- a/src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs @@ -22,6 +22,9 @@ public static class FriendlyPublishedContentExtensions private static IPublishedContentCache PublishedContentCache { get; } = StaticServiceProvider.Instance.GetRequiredService(); + private static IPublishedMediaCache PublishedMediaCache { get; } = + StaticServiceProvider.Instance.GetRequiredService(); + private static IDocumentNavigationQueryService DocumentNavigationQueryService { get; } = StaticServiceProvider.Instance.GetRequiredService(); @@ -77,6 +80,20 @@ private static INavigationQueryService GetNavigationQueryService(IPublishedConte } } + + private static IPublishedCache GetPublishedCache(IPublishedContent content) + { + switch (content.ContentType.ItemType) + { + case PublishedItemType.Content: + return PublishedContentCache; + case PublishedItemType.Media: + return PublishedMediaCache; + default: + throw new NotSupportedException("Unsupported content type."); + } + } + /// /// Creates a strongly typed published content model for an internal published content. /// @@ -223,7 +240,7 @@ public static bool HasValue( /// set to 1. /// public static IPublishedContent Root(this IPublishedContent content) - => content.Root(PublishedContentCache, GetNavigationQueryService(content)); + => content.Root(GetPublishedCache(content), GetNavigationQueryService(content)); /// /// Gets the root content (ancestor or self at level 1) for the specified if it's of the @@ -242,7 +259,7 @@ public static IPublishedContent Root(this IPublishedContent content) /// public static T? Root(this IPublishedContent content) where T : class, IPublishedContent - => content.Root(PublishedContentCache, GetNavigationQueryService(content)); + => content.Root(GetPublishedCache(content), GetNavigationQueryService(content)); /// /// Gets the parent of the content item. @@ -252,7 +269,7 @@ public static IPublishedContent Root(this IPublishedContent content) /// The parent of content of the specified content type or null. public static T? Parent(this IPublishedContent content) where T : class, IPublishedContent - => content.Parent(PublishedContentCache, GetNavigationQueryService(content)); + => content.Parent(GetPublishedCache(content), GetNavigationQueryService(content)); /// /// Gets the ancestors of the content. @@ -261,7 +278,7 @@ public static IPublishedContent Root(this IPublishedContent content) /// The ancestors of the content, in down-top order. /// Does not consider the content itself. public static IEnumerable Ancestors(this IPublishedContent content) - => content.Ancestors(PublishedContentCache, GetNavigationQueryService(content)); + => content.Ancestors(GetPublishedCache(content), GetNavigationQueryService(content)); /// /// Gets the content and its ancestors. @@ -269,7 +286,7 @@ public static IEnumerable Ancestors(this IPublishedContent co /// The content. /// The content and its ancestors, in down-top order. public static IEnumerable AncestorsOrSelf(this IPublishedContent content) - => content.AncestorsOrSelf(PublishedContentCache, GetNavigationQueryService(content)); + => content.AncestorsOrSelf(GetPublishedCache(content), GetNavigationQueryService(content)); /// /// Gets the content and its ancestors, of a specified content type. @@ -280,7 +297,7 @@ public static IEnumerable AncestorsOrSelf(this IPublishedCont /// May or may not begin with the content itself, depending on its content type. public static IEnumerable AncestorsOrSelf(this IPublishedContent content) where T : class, IPublishedContent - => content.AncestorsOrSelf(PublishedContentCache, GetNavigationQueryService(content)); + => content.AncestorsOrSelf(GetPublishedCache(content), GetNavigationQueryService(content)); /// /// Gets the ancestor of the content, i.e. its parent. @@ -288,7 +305,7 @@ public static IEnumerable AncestorsOrSelf(this IPublishedContent content) /// The content. /// The ancestor of the content. public static IPublishedContent? Ancestor(this IPublishedContent content) - => content.Ancestor(PublishedContentCache, GetNavigationQueryService(content)); + => content.Ancestor(GetPublishedCache(content), GetNavigationQueryService(content)); /// /// Gets the nearest ancestor of the content, of a specified content type. @@ -299,7 +316,7 @@ public static IEnumerable AncestorsOrSelf(this IPublishedContent content) /// Does not consider the content itself. May return null. public static T? Ancestor(this IPublishedContent content) where T : class, IPublishedContent - => content.Ancestor(PublishedContentCache, GetNavigationQueryService(content)); + => content.Ancestor(GetPublishedCache(content), GetNavigationQueryService(content)); /// /// Gets the content or its nearest ancestor, of a specified content type. @@ -310,7 +327,7 @@ public static IEnumerable AncestorsOrSelf(this IPublishedContent content) /// May or may not return the content itself depending on its content type. May return null. public static T? AncestorOrSelf(this IPublishedContent content) where T : class, IPublishedContent - => content.AncestorOrSelf(PublishedContentCache, GetNavigationQueryService(content)); + => content.AncestorOrSelf(GetPublishedCache(content), GetNavigationQueryService(content)); /// /// Returns all DescendantsOrSelf of all content referenced @@ -327,7 +344,7 @@ public static IEnumerable AncestorsOrSelf(this IPublishedContent content) /// public static IEnumerable DescendantsOrSelfOfType( this IEnumerable parentNodes, string docTypeAlias, string? culture = null) - => parentNodes.DescendantsOrSelfOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(parentNodes.First()), docTypeAlias, culture); + => parentNodes.DescendantsOrSelfOfType(VariationContextAccessor, GetPublishedCache(parentNodes.First()), GetNavigationQueryService(parentNodes.First()), docTypeAlias, culture); /// /// Returns all DescendantsOrSelf of all content referenced @@ -345,77 +362,77 @@ public static IEnumerable DescendantsOrSelf( this IEnumerable parentNodes, string? culture = null) where T : class, IPublishedContent - => parentNodes.DescendantsOrSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(parentNodes.First()), culture); + => parentNodes.DescendantsOrSelf(VariationContextAccessor, GetPublishedCache(parentNodes.First()), GetNavigationQueryService(parentNodes.First()), culture); public static IEnumerable Descendants(this IPublishedContent content, string? culture = null) - => content.Descendants(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); + => content.Descendants(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture); public static IEnumerable Descendants(this IPublishedContent content, int level, string? culture = null) - => content.Descendants(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), level, culture); + => content.Descendants(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), level, culture); public static IEnumerable DescendantsOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) - => content.DescendantsOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), contentTypeAlias, culture); + => content.DescendantsOfType(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), contentTypeAlias, culture); public static IEnumerable Descendants(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent - => content.Descendants(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); + => content.Descendants(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture); public static IEnumerable Descendants(this IPublishedContent content, int level, string? culture = null) where T : class, IPublishedContent - => content.Descendants(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), level, culture); + => content.Descendants(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), level, culture); public static IEnumerable DescendantsOrSelf( this IPublishedContent content, string? culture = null) - => content.DescendantsOrSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); + => content.DescendantsOrSelf(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture); public static IEnumerable DescendantsOrSelf(this IPublishedContent content, int level, string? culture = null) - => content.DescendantsOrSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), level, culture); + => content.DescendantsOrSelf(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), level, culture); public static IEnumerable DescendantsOrSelfOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) - => content.DescendantsOrSelfOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), contentTypeAlias, culture); + => content.DescendantsOrSelfOfType(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), contentTypeAlias, culture); public static IEnumerable DescendantsOrSelf(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent - => content.DescendantsOrSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); + => content.DescendantsOrSelf(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture); public static IEnumerable DescendantsOrSelf(this IPublishedContent content, int level, string? culture = null) where T : class, IPublishedContent - => content.DescendantsOrSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), level, culture); + => content.DescendantsOrSelf(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), level, culture); public static IPublishedContent? Descendant(this IPublishedContent content, string? culture = null) - => content.Descendant(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); + => content.Descendant(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture); public static IPublishedContent? Descendant(this IPublishedContent content, int level, string? culture = null) - => content.Descendant(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), level, culture); + => content.Descendant(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), level, culture); public static IPublishedContent? DescendantOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) - => content.DescendantOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), contentTypeAlias, culture); + => content.DescendantOfType(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), contentTypeAlias, culture); public static T? Descendant(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent - => content.Descendant(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); + => content.Descendant(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture); public static T? Descendant(this IPublishedContent content, int level, string? culture = null) where T : class, IPublishedContent - => content.Descendant(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), level, culture); + => content.Descendant(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), level, culture); public static IPublishedContent DescendantOrSelf(this IPublishedContent content, string? culture = null) => content.DescendantOrSelf(VariationContextAccessor, culture); public static IPublishedContent? DescendantOrSelf(this IPublishedContent content, int level, string? culture = null) - => content.DescendantOrSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), level, culture); + => content.DescendantOrSelf(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), level, culture); public static IPublishedContent? DescendantOrSelfOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) - => content.DescendantOrSelfOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), contentTypeAlias, culture); + => content.DescendantOrSelfOfType(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), contentTypeAlias, culture); public static T? DescendantOrSelf(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent - => content.DescendantOrSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); + => content.DescendantOrSelf(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture); public static T? DescendantOrSelf(this IPublishedContent content, int level, string? culture = null) where T : class, IPublishedContent - => content.DescendantOrSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), level, culture); + => content.DescendantOrSelf(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), level, culture); /// /// Gets the children of the content item. @@ -443,7 +460,7 @@ public static IPublishedContent DescendantOrSelf(this IPublishedContent content, /// /// public static IEnumerable Children(this IPublishedContent content, string? culture = null) - => content.Children(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); + => content.Children(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture); /// /// Gets the children of the content, filtered by a predicate. @@ -462,7 +479,7 @@ public static IEnumerable Children(this IPublishedContent con this IPublishedContent content, Func predicate, string? culture = null) - => content.Children(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), predicate, culture); + => content.Children(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), predicate, culture); /// /// Gets the children of the content, of any of the specified types. @@ -475,7 +492,7 @@ public static IEnumerable Children(this IPublishedContent con /// The content type alias. /// The children of the content, of any of the specified types. public static IEnumerable? ChildrenOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) - => content.ChildrenOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), contentTypeAlias, culture); + => content.ChildrenOfType(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), contentTypeAlias, culture); /// /// Gets the children of the content, of a given content type. @@ -492,30 +509,30 @@ public static IEnumerable Children(this IPublishedContent con /// public static IEnumerable? Children(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent - => content.Children(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); + => content.Children(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture); public static IPublishedContent? FirstChild(this IPublishedContent content, string? culture = null) - => content.FirstChild(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); + => content.FirstChild(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture); /// /// Gets the first child of the content, of a given content type. /// public static IPublishedContent? FirstChildOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) - => content.FirstChildOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), contentTypeAlias, culture); + => content.FirstChildOfType(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), contentTypeAlias, culture); public static IPublishedContent? FirstChild(this IPublishedContent content, Func predicate, string? culture = null) - => content.FirstChild(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), predicate, culture); + => content.FirstChild(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), predicate, culture); public static IPublishedContent? FirstChild(this IPublishedContent content, Guid uniqueId, string? culture = null) - => content.FirstChild(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), uniqueId, culture); + => content.FirstChild(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), uniqueId, culture); public static T? FirstChild(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent - => content.FirstChild(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); + => content.FirstChild(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture); public static T? FirstChild(this IPublishedContent content, Func predicate, string? culture = null) where T : class, IPublishedContent - => content.FirstChild(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), predicate, culture); + => content.FirstChild(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), predicate, culture); /// /// Gets the siblings of the content. @@ -530,7 +547,7 @@ public static IEnumerable Children(this IPublishedContent con /// Note that in V7 this method also return the content node self. /// public static IEnumerable? Siblings(this IPublishedContent content, string? culture = null) - => content.Siblings(PublishedContentCache, GetNavigationQueryService(content), VariationContextAccessor, culture); + => content.Siblings(GetPublishedCache(content), GetNavigationQueryService(content), VariationContextAccessor, culture); /// /// Gets the siblings of the content, of a given content type. @@ -546,7 +563,7 @@ public static IEnumerable Children(this IPublishedContent con /// Note that in V7 this method also return the content node self. /// public static IEnumerable? SiblingsOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) - => content.SiblingsOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), contentTypeAlias, culture); + => content.SiblingsOfType(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), contentTypeAlias, culture); /// /// Gets the siblings of the content, of a given content type. @@ -563,7 +580,7 @@ public static IEnumerable Children(this IPublishedContent con /// public static IEnumerable? Siblings(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent - => content.Siblings(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); + => content.Siblings(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture); /// /// Gets the siblings of the content including the node itself to indicate the position. @@ -577,7 +594,7 @@ public static IEnumerable Children(this IPublishedContent con public static IEnumerable? SiblingsAndSelf( this IPublishedContent content, string? culture = null) - => content.SiblingsAndSelf(PublishedContentCache, GetNavigationQueryService(content), VariationContextAccessor, culture); + => content.SiblingsAndSelf(GetPublishedCache(content), GetNavigationQueryService(content), VariationContextAccessor, culture); /// /// Gets the siblings of the content including the node itself to indicate the position, of a given content type. @@ -593,7 +610,7 @@ public static IEnumerable Children(this IPublishedContent con this IPublishedContent content, string contentTypeAlias, string? culture = null) - => content.SiblingsAndSelfOfType(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), contentTypeAlias, culture); + => content.SiblingsAndSelfOfType(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), contentTypeAlias, culture); /// /// Gets the siblings of the content including the node itself to indicate the position, of a given content type. @@ -607,7 +624,7 @@ public static IEnumerable Children(this IPublishedContent con /// The siblings of the content including the node itself, of the given content type. public static IEnumerable? SiblingsAndSelf(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent - => content.SiblingsAndSelf(VariationContextAccessor, PublishedContentCache, GetNavigationQueryService(content), culture); + => content.SiblingsAndSelf(VariationContextAccessor, GetPublishedCache(content), GetNavigationQueryService(content), culture); /// /// Gets the url of the content item. @@ -642,7 +659,7 @@ public static DataTable ChildrenAsTable(this IPublishedContent content, string c => content.ChildrenAsTable( VariationContextAccessor, - PublishedContentCache, + GetPublishedCache(content), GetNavigationQueryService(content), ContentTypeService, MediaTypeService,