SkillAgentSearch skills...

ArgumentativeFilters

A source generator for MinimalAPI filters that make use of handler arguments.

Install / Use

/learn @hwoodiwiss/ArgumentativeFilters
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Argumentative Filters

NuGet

:warning: This package is currently in preview, and is subject to change.

Background

In classic ASP.Net Core APIs, IActionFilter.ActionExecutingContext provides access to IDictionary<string, object?> ActionArguments which is a name-value collection of the parameters that will be provided to the Controller action that will be run.

There isn't a direct equivalent to that in AspNetCore Minimal APIs, instead, an EndpointFilterInvocationContext is passed, which instead has in IList<object?> Arguments for accessing the Minimal API endpoint delegate argument values.

To be able to access arguments by name, a filter factory must be created that takes an EndpointFilterFactoryContext which contains a MethodInfo representing the endpoint delegate, from which you can retrieve the parameter position of the parameters by name, and use that to index into the Arguments collection.

If that sounds a bit labour intensive, that's because it is. That's where Argumentative Filters come in.

With Argumentative Filters, a filter can be created as a static method that takes an EndpointFilterInvocationContext and an EndpointFilterDelegate as required parameters. Other kinds of parameters are also supported, documentation for these can be found here.

Usage

Filter

public static partial class ExampleFilter
{
    [ArgumentativeFilter]
    public static ValueTask<object?> NormalizeParameterCase(EndpointFilterInvocationContext context, EndpointFilterDelegate next, string parameter, [IndexOf(nameof(parameter))] int parameterIndex)
    {
        context.Arguments[parameterIndex] = parameter.ToUpperInvariant();
        return next(context);
    }
}

Minimal API Route Configuration

app.MapGet("/my/route/{parameter}", (string parameter) => parameter)
    .AddEndpointFilterFactory(ExampleFilter.Factory);
View on GitHub
GitHub Stars11
CategoryDevelopment
Updated5d ago
Forks0

Languages

C#

Security Score

90/100

Audited on Apr 2, 2026

No findings