Skip to content

[release/6.0-rc1] Add ParameterInfo argument to BindAsync and return specific type instead of object#35795

Merged
dougbu merged 4 commits intorelease/6.0-rc1from
backport/pr-35791-to-release/6.0-rc1
Aug 27, 2021
Merged

[release/6.0-rc1] Add ParameterInfo argument to BindAsync and return specific type instead of object#35795
dougbu merged 4 commits intorelease/6.0-rc1from
backport/pr-35791-to-release/6.0-rc1

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Aug 26, 2021

Backport of #35791 to release/6.0-rc1

/cc @halter73

Customer Impact

Before rc1, customers who wanted to advanced parameter binding with minimal API giving full access to the request's HttpContext, could not do so.

In rc1, we added support for parameter binding via a public static BindAsync method on the parameter's declaring type:

public static ValueTask<object?> BindAsync(HttpContext context);

The big thing it's missing is details about the parameter other than the type like the parameter's name and attributes, so we decided to add a ParameterInfo argument to BindAsync. We also decided that it would be better to require the return type to be ValueTask<{DeclaringType}> instead of ValueTask<object?> for better type-safety.

So after this change, we will not look for the old BindAsync signature on the parameter's declaring type, but instead the following:

public static ValueTask<{DeclaringType}> BindAsync(HttpContext context, ParameterInfo parameter);

Before:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/webhook", (CloudEvent cloudEvent) =>
{
    redis.Publish(cloudEvent);
});

app.Run();

public class CloudEvent
{
    public static async ValueTask<object?> BindAsync(HttpContext context)
    {
        return await CloudEventParser.ReadEventAsync(context);
    }
}

After:

public class CloudEvent
{
    public static async ValueTask<CloudEvent?> BindAsync(HttpContext context, ParameterInfo parameter)
    {
        return await CloudEventParser.ReadEventAsync(context, parameter.Name);
    }
}

We don't want to have a breaking change between rc1 and rc2 which is why we're asking to get this change in rc1 now.

Regression?

  • Yes
  • No

Packaging changes reviewed?

  • Yes
  • No
  • N/A

Verification

  • Manual (required)
  • Automated

Risk

  • High
  • Medium
  • Low

Support for BindAsync is entirely new in rc1.

@Pilchie Pilchie added the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Aug 26, 2021
@github-actions github-actions bot requested a review from javiercn as a code owner August 26, 2021 22:26
@dougbu dougbu added the Servicing-approved Shiproom has approved the issue label Aug 27, 2021
@dougbu dougbu merged commit 1a0e38b into release/6.0-rc1 Aug 27, 2021
@dougbu dougbu deleted the backport/pr-35791-to-release/6.0-rc1 branch August 27, 2021 03:58
@ghost ghost added this to the 6.0-rc1 milestone Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels Servicing-approved Shiproom has approved the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants