-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Added support for type based parameter binding #35496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Added a convention that allows custom async binding logic to run for parameters that have a static BindAsync method that takes an HttpContext and return a ValueTask of object. This allows customers to write custom binders based solely on type (it's an extension of the existing TryParse pattern). - There's allocation overhead per request once there's a parameter binder for a delegate. This is because we need to box all of the arguments since we're not using generated code to compute data from the list of binders. - Changed TryParse tests to BindAsync tests and added more tests.
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/backport release/6.0-rc1 |
/backport to release/6.0-rc1 |
Started backporting to release/6.0-rc1: https://github.com/dotnet/aspnetcore/actions/runs/1148811785 |
@davidfowl backporting to release/6.0-rc1 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Added support for type based parameter binding - Added a convention that allows custom async binding logic to run for parameters that have a static BindAsync method that takes an HttpContext and return a ValueTask of object. This allows customers to write custom binders based solely on type (it's an extension of the existing TryParse pattern). - There's allocation overhead per request once there's a parameter binder for a delegate. This is because we need to box all of the arguments since we're not using generated code to compute data from the list of binders. - Changed TryParse tests to BindAsync tests and added more tests.
Using index info to reconstruct a base tree...
M src/Http/Http.Extensions/src/RequestDelegateFactory.cs
M src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs
M src/Http/Http.Extensions/test/TryParseMethodCacheTests.cs
M src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs
M src/Shared/TryParseMethodCache.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Shared/TryParseMethodCache.cs
CONFLICT (content): Merge conflict in src/Shared/TryParseMethodCache.cs
Auto-merging src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs
CONFLICT (content): Merge conflict in src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs
Auto-merging src/Http/Http.Extensions/test/TryParseMethodCacheTests.cs
CONFLICT (content): Merge conflict in src/Http/Http.Extensions/test/TryParseMethodCacheTests.cs
Auto-merging src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs
CONFLICT (content): Merge conflict in src/Http/Http.Extensions/test/RequestDelegateFactoryTests.cs
Auto-merging src/Http/Http.Extensions/src/RequestDelegateFactory.cs
CONFLICT (content): Merge conflict in src/Http/Http.Extensions/src/RequestDelegateFactory.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Added support for type based parameter binding - Added a convention that allows custom async binding logic to run for parameters that have a static BindAsync method that takes an HttpContext and return a ValueTask of object. This allows customers to write custom binders based solely on type (it's an extension of the existing TryParse pattern). - There's allocation overhead per request once there's a parameter binder for a delegate. This is because we need to box all of the arguments since we're not using generated code to compute data from the list of binders. - Changed TryParse tests to BindAsync tests and added more tests.
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
* Added support for type based parameter binding - Added a convention that allows custom async binding logic to run for parameters that have a static BindAsync method that takes an HttpContext and return a ValueTask of object. This allows customers to write custom binders based solely on type (it's an extension of the existing TryParse pattern). - There's allocation overhead per request once there's a parameter binder for a delegate. This is because we need to box all of the arguments since we're not using generated code to compute data from the list of binders. - Changed TryParse tests to BindAsync tests and added more tests.
Now that public interface ITypeBindAsync {
static abstract ValueTask<object?> BindAsync(HttpContext context);
} It wouldn't make it easier to call, though, since you can't exactly go But it would be easier and probably quicker to find out if a type is compliant or not - look for the type implementing the interface instead of looking for the method implementation. Then again, you still have to have the method to actually call it the way this is implemented now, through expression tree compilation. And of course, if you wanted the pattern to be usable without implementing an interface, that change couldn't be made. Basically, the patch is probably the best way to do it, but it's fun to finally be able to think about statics in interfaces! |
Hi @JesperTreetop. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
Usage: