Class ServiceCollectionExtensions
- Namespace
- Ramstack.HtmxToolkit.Hosting
- Assembly
- Ramstack.HtmxToolkit.dll
Provides HtmxToolkit service registration for an IServiceCollection.
public static class ServiceCollectionExtensions
- Inheritance
-
ServiceCollectionExtensions
- Inherited Members
Methods
AddHtmxToolkit(IServiceCollection, Action<HtmxToolkitOptions>)
Registers and configures HtmxToolkit services.
public static IServiceCollection AddHtmxToolkit(this IServiceCollection services, Action<HtmxToolkitOptions> configure)
Parameters
servicesIServiceCollectionThe service collection.
configureAction<HtmxToolkitOptions>The delegate used to configure HtmxToolkit.
Returns
- IServiceCollection
The same
servicescollection.
Examples
using Ramstack.HtmxToolkit.Hosting;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
// Select the version that your pages load, and set only
// the HTMX options that should differ from the HTMX defaults.
builder.Services.AddHtmxToolkit(options =>
{
options.UseHtmxV4(config =>
{
config.DefaultTimeout = 10_000;
});
});
Remarks
The delegate must select the HTMX version with UseHtmxV1(Action<HtmxV1Config>?), UseHtmxV2(Action<HtmxV2Config>?), or UseHtmxV4(Action<HtmxV4Config>?); otherwise, the application fails to start.