Skip to content

Add support for custom model binders in minimal APIs #35472

Closed
@lomholdt

Description

@lomholdt

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");

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions