Closed
Description
Today, if you want to support an optional parameter with BindAsync, you cannot use a nullable struct. Instead you must use a reference type.
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
// cloudEvent will be inferred to come from a Json request body because no BindAsync method will
// be found on Nullable<CloudEventStruct> and RequestDelegateFactory doesn't try to unwrap the nullable.
app.MapGet("/webhook", (CloudEventStruct? cloudEvent) =>
{
redis.Publish(cloudEvent);
});
app.Run();
public struct CloudEventStruct
{
// This will NOT be matched because it returns returns a ValueTask<CloudEventStruct?>
// instead of ValueTask<CloudEventStruct>
public static async ValueTask<CloudEventStruct?> BindAsync(HttpContext context, ParameterInfo parameter)
{
return await CloudEventParser.ReadEventAsync(context, parameter.Name);
}
}
This tracks adding support for nullable-struct parameters and nullable-struct-returning BindAsync methods.
Metadata
Metadata
Labels
Work that is important, but not critical for the releaseIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcThis issue represents an ask for new feature or an enhancement to an existing oneController-like actions for endpoint routing*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels