Table of Contents

Class BuilderBasedNavProvider

Namespace
Htmx.Components.NavBar
Assembly
Htmx.Components.dll

A navigation provider that builds its navigation action set via a given builder factory delegate.

public class BuilderBasedNavProvider : INavProvider
Inheritance
BuilderBasedNavProvider
Implements
Inherited Members
Extension Methods

Examples

Configure programmatic navigation during service registration:

services.AddHtmxComponents(options =>
{
    options.WithNavBuilder(async builder =>
    {
        builder.AddAction(action => action
            .WithLabel("Dashboard")
            .WithIcon("fas fa-dashboard")
            .WithHxGet("/Dashboard"));

        builder.AddGroup(group =>
        {
            group.WithLabel("Administration");
            group.AddAction(action => action.WithLabel("Users").WithHxGet("/Admin/Users"));
        });
    });
});

Remarks

This provider is useful when you want to programmatically define navigation structure rather than using attributes. The builder factory is called each time navigation is requested, allowing for dynamic navigation based on current context.

Constructors

BuilderBasedNavProvider(IServiceProvider, Func<ActionSetBuilder, Task>)

Initializes a new instance of the BuilderBasedNavProvider class.

public BuilderBasedNavProvider(IServiceProvider serviceProvider, Func<ActionSetBuilder, Task> builderFactory)

Parameters

serviceProvider IServiceProvider

The service provider for dependency resolution.

builderFactory Func<ActionSetBuilder, Task>

The factory function that configures the navigation builder.

Exceptions

ArgumentNullException

Thrown when any parameter is null.

Methods

BuildAsync()

Builds the navigation action set using the configured builder factory.

public Task<IActionSet> BuildAsync()

Returns

Task<IActionSet>

A task that represents the asynchronous operation. The task result contains the navigation action set.