INavigationTreeBuilder isn't created with navigation.json
Closed this issue · 3 comments
Basically as the title says. I have everything working okay but when I try and use a navigation.json
instead the site crashes on the home page with a NullReferenceException
for INavigationTreeBuilder
. I followed the instructions and added the relevant section to appsettings.json
as show below.
"NavigationOptions": {
"RootTreeBuilderName": "cloudscribe.Web.Navigation.JsonNavigationTreeBuilder",
"NavigationMapXmlFileName": "navigation.xml",
"NavigationMapJsonFileName": "navigation.json"
}
If I substitute Json
for Xml
in the top line above, everything works as expected.
Thanks in advance :-)
In addition to the config change, in order to use Json you also need this:
services.AddScoped<INavigationTreeBuilder, JsonNavigationTreeBuilder>();
No joy I'm afraid. Here's my full ConfigureServices
method:
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
services.AddScoped(x => x.GetRequiredService<IUrlHelperFactory>().
GetUrlHelper(x.GetRequiredService<IActionContextAccessor>().ActionContext));
services.AddCloudscribeNavigation(Configuration.GetSection("NavigationOptions"));
services.AddScoped<INavigationTreeBuilder, JsonNavigationTreeBuilder>();
services.AddScoped<IOrderService, OrderService>();
services.AddScoped<IProductService, ProductService>();
services.AddScoped<IUserService, UserService>();
services.AddRouting(x => x.LowercaseUrls = true);
services.AddMvc(x =>
{
x.EnableEndpointRouting = true;
x.Filters.Add(typeof(Breadcrumbs));
})
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddRazorRuntimeCompilation();
}
My sample project can be found here. FWIW I tried downloading your sample project and also couldn't get that to work.
I found the problem. The JsonNavigationTreeBuilder was returning a short name rather than the fully qualified type name and this was causing it to fail to find that tree builder by name. I've fixed this and published a new nuget: https://www.nuget.org/packages/cloudscribe.Web.Navigation/4.0.1
Thanks for letting us know about this issue.