Skip to content

Add support for custom model binders in minimal APIs #35472

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

Closed
lomholdt opened this issue Aug 18, 2021 · 1 comment
Closed

Add support for custom model binders in minimal APIs #35472

lomholdt opened this issue Aug 18, 2021 · 1 comment
Labels
old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Comments

@lomholdt
Copy link

Is your feature request related to a problem? Please describe.

I am trying to use a custom model binder in the new minimal APIs but it does not seem that this is possible at the moment.

In the controller based approach I could create a custom binder as such

public class CustomBinder<TEvent> : IModelBinder { ... }

public class CustomBinderProvider : IModelBinderProvider { ... }

and register it in Startup.ConfigureServices

services.AddControllers(options =>
{
    options.ModelBinderProviders.Insert(0, new CustomBinderProvider());
});

and then use it

[HttpPost("foo-endpoint")]
public IActionResult Post(Foo customType) => Ok();

Where the CustomBinderProvider would react to the Foo and use the CustomBinder.

Describe the solution you'd like

Using a custom model binding in the minimal API setup so it's possible to do the same as described above, or achieve the same result.

app.MapPost("foo-endpoint", (Foo customType) => "ok");
@pranavkm pranavkm 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 18, 2021
@DamianEdwards
Copy link
Member

We're tracking discussion of future support for customizing parameter binding in Minimal APIs in #35489

@ghost ghost locked as resolved and limited conversation to collaborators Sep 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Projects
None yet
Development

No branches or pull requests

3 participants