Professionally I'm a primarily back-end developer using dotnet on AWS.
Aside from that I love C++ and Rust, and enjoy Embedded Systems, Security and Graphics programming.
A source generator for MinimalAPI filters that make use of handler arguments.
License: MIT License
From looking at the example in the README, it looks like a nice feature would be to have an attribute that could only be used with a ref
parameter.
So the example would become this:
public static partial class ExampleFilter
{
[ArgumentativeFilter]
public static ValueTask<object?> NormalizeParameterCase(EndpointFilterInvocationContext context, EndpointFilterDelegate next, [ArgumentRef] ref string parameter)
{
parameter = parameter.ToUpperInvariant();
return next(context);
}
}
The code gen would ref return the value from the context.Arguments
array behind the scenes, reusing the existing IndexOf
functionality.
At the moment, using aren't being added to the generated factory code for the types provided in the filter.
This will cause build errors an all but fairly trivial cases.
Example with annotated failures:
// <auto-generated/>
using global::System;
using global::Microsoft.AspNetCore.Http;
#nullable enable
namespace SomeNamespace.Filters
{
public static partial class SomeRequestValidationFilter
{
public static EndpointFilterDelegate Factory(EndpointFilterFactoryContext context, EndpointFilterDelegate next)
{
int? argumentNameIndex = context.GetArgumentIndex("argumentName");
if (argumentNameIndex.HasValue)
{
return invocationFilterContext => {
var applicationOptionsService = invocationFilterContext.HttpContext.RequestServices.GetService<SomeOptions>(); <- This fails, missing Microsoft.Extensions.DependencyInjection and namespace for SomeOptions
var requestContextService = invocationFilterContext.HttpContext.RequestServices.GetService<SomeRequestContext>(); <- This fails, missing Microsoft.Extensions.DependencyInjection and namespace SomeRequestContext
var clientContextService = invocationFilterContext.HttpContext.RequestServices.GetService<SomeClientContext>();
var someApiOptionsService = invocationFilterContext.HttpContext.RequestServices.GetService<SomeApiOptions>();
string argumentValue = invocationFilterContext.GetArgument<string>(argumentNameIndex.Value);
return Filter(invocationFilterContext, next, applicationOptionsService, requestContextService, clientContextService, someApiOptionsService , argumentValue);
};
}
return next;
}
private static int? GetArgumentIndex(this EndpointFilterFactoryContext context, string argumentName)
=> context.MethodInfo.GetParameters().FirstOrDefault(p => string.Equals(p.Name, argumentName, StringComparison.Ordinal))?.Position;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.