Hi,
Using the new .Children overload in v15 (the old method being marked as obsolete), the build process can never activate INavigationQueryService
:
AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: MyApp.IMyService Lifetime: Scoped ImplementationType: MyApp.MyService': Unable to resolve service for type 'Umbraco.Cms.Core.Services.Navigation.INavigationQueryService' while attempting to activate MyApp.MyService'.)
The recommended approach to replace the obsolete .Children is to use the overload accepting INavigationQueryService
and IPublishedStatusFilteringService
:
public class MyService(IUmbracoContextAccessor umbracoContextAccessor,
INavigationQueryService navigationQueryService,
IPublishedStatusFilteringService publishedStatusFilteringService) : IMyService
{
public IEnumerable<MyType> GetData()
{
if (umbracoContextAccessor?.TryGetUmbracoContext(out var umbracoContext) != true)
{
return [];
}
var myData = umbracoContext?.Content.GetById("someGuid");
return myData.Children(navigationQueryService, publishedStatusFilteringService).OfType<TechCategory>();
}
}
Why can this not resolve?
For detail, MyService : IMyService is defined in a class library
public static IServiceCollection AddWebServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddScoped<IMyService, MyService>();
return services;
}
}
this is referenced in my Umbraco/Web Program.cs
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.CreateUmbracoBuilder()
.AddBackOffice()
.AddWebsite()
.AddDeliveryApi()
.AddComposers()
.Build();
builder.Services.AddCommonServices(builder.Configuration);
builder.Services.AddWebServices(builder.Configuration);
I have tried changing the ordering of this, but it makes no difference.
I figure I am missing something obvious here.