Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V15: Replacing the usages of Children (navigation data) from IPublishedContent #17159

Prev Previous commit
Next Next commit
Introduce GetParent() which uses the right services
elit0451 committed Sep 30, 2024
commit 52c64fba402789f385d3a43c013eef3384e943aa
27 changes: 24 additions & 3 deletions src/Umbraco.PublishedCache.HybridCache/PublishedContent.cs
Original file line number Diff line number Diff line change
@@ -164,9 +164,8 @@ public override int Level
}
}

[Obsolete("Please use IDocumentNavigationQueryService.TryGetParentKey() instead. Scheduled for removal in V16.")]
public override IPublishedContent? Parent
=> this.Parent<IPublishedContent>(StaticServiceProvider.Instance.GetRequiredService<IPublishedContentCache>(), StaticServiceProvider.Instance.GetRequiredService<IDocumentNavigationQueryService>());
[Obsolete("Please use TryGetParentKey() on IDocumentNavigationQueryService or IMediaNavigationQueryService instead. Scheduled for removal in V16.")]
public override IPublishedContent? Parent => GetParent();

/// <inheritdoc />
public override IReadOnlyDictionary<string, PublishedCultureInfo> Cultures
@@ -269,4 +268,26 @@ public override bool IsPublished(string? culture = null)
// = depends on the culture
return _contentNode.HasPublishedCulture(culture);
}

private IPublishedContent? GetParent()
{
INavigationQueryService? navigationQueryService;
IPublishedCache? publishedCache;

switch (ContentType.ItemType)
{
case PublishedItemType.Content:
publishedCache = StaticServiceProvider.Instance.GetRequiredService<IPublishedContentCache>();
navigationQueryService = StaticServiceProvider.Instance.GetRequiredService<IDocumentNavigationQueryService>();
break;
case PublishedItemType.Media:
publishedCache = StaticServiceProvider.Instance.GetRequiredService<IPublishedMediaCache>();
navigationQueryService = StaticServiceProvider.Instance.GetRequiredService<IMediaNavigationQueryService>();
break;
default:
throw new NotImplementedException("Level is not implemented for " + ContentType.ItemType);
}

return this.Parent<IPublishedContent>(publishedCache, navigationQueryService);
}
}