INavigationProvider
The INavigationProvider is used by the navigation component to display the site navigation, usually based on the pages which have been created on the website. To display pages, the PageNavigatorProvider (which is an implementation of the INavigationProvider) is used. If you would like to display custom data in the navigation component, you can implement your own INavigationProvider.
Interface declaration
public interface INavigationProvider { Task<IEnumerable<NavigationNode>> GetNavigationNodes(NavigationNode parentNode); Task<NavigationNode> GetRootNode(); void SetContext(PageRequest pageRequest, DataBindingContext dataBindingContext); }
Example
In this example, we are simply returning a static list of NavigationNodes.
[DisplayName("Test navigation provider")] [Description("Returns some static navigation nodes for demonstration purposes")] public class TestNavigationProvider : INavigationProvider { public async Task<IEnumerable<NavigationNode>> GetNavigationNodes(NavigationNode parentNode) { var nodes = new List<NavigationNode>(); if (parentNode.Id == Guid.Empty) { nodes.Add(new NavigationNode() { Id = Guid.NewGuid(), Text = "Node 1", NavigationProvider = this, Url = new Url("/node1"), ChildCount = 0 }); nodes.Add(new NavigationNode() { Id = Guid.NewGuid(), Text = "Node 2", NavigationProvider = this, Url = new Url("/node2"), ChildCount = 0 }); } return await Task.FromResult(nodes); } public async Task<NavigationNode> GetRootNode() { return await Task.FromResult(new NavigationNode() { Id = Guid.Empty, NavigationProvider = this, ProviderItem = null, Text = "", Url = null, Level = 0, IsChildSelected = true, }); } public void SetContext(PageRequest pageRequest, DataBindingContext dataBindingContext) { //not needed here as we are not using the pageRequest or dataBindingContext on this implementation. } }
Registration
This is how the implementation is registered into the DI container in Veva, this should be done in your module config file (The class which implements IModule).
public void ConfigureServices(IServiceCollection services, IConfiguration configuration) { services.AddNamed<INavigationProvider, TestNavigationProvider>(ServiceLifetime.Transient); }
Usage
Once your implementation has been registered to the services collection, you should be able to selected it from the list of available providers in the Navigation menu component. Once selected, your static nodes should appear.