Closed artyom-p closed 4 years ago
Not yet. HeaderModelBinder exists in the aspnet/Mvc repo., but it's for very simple situations. I don't know why Microsoft never added a HeaderValueProvider
to go with the other value providers. I postponed writing my own thinking they would eventually do it...
🎉 https://www.nuget.org/packages/HybridModelBinding/0.13.0
public class Person
{
[From(Source.Header)]
public int Age { get; set; }
}
curl -X GET \
http://localhost/ \
-H 'Age: 42'
Wow, thank you!
Hey, binding works perfectly, just a small proposal, it would be great to have a possibility to override a binding name.
For example i have a header - x-request-id, and by default binder is unable to bind header to property RequestId (unfortunately it's no possible to use dashes in names).
As a solution, aditional parameter for an attribute could work. This could be also helpful not only for header binding.
https://www.nuget.org/packages/HybridModelBinding/0.14.0 implements a new [HybridBindProperty]
-attribute that will allow you to reference a separate header-name. There are some additional features which can be found in the README.
That's a great news! Great update!
Doing some belated house cleaning. Issue has been resolved.
Is it possible somehow to bind properties to header values?