3 ms·
It's a language/framework issue. C# supports first class properties with get/set semantics. In your method (actions) in the controller you would write something
by scarface74 10y ago
It's a language/framework issue. C# supports first class properties with get/set semantics. In your method (actions) in the controller you would write something like this:
public List<CustomerModel> Get(SearchRequest request)
{
.....
return customers;
}
Somewhere else in the (configurable) pipeline the framework can decide how to deserialize the SearchRequest and how to serialize the List<customer> based on the Accept-Header.
(CustomerModel/Request would not be business objects. They would only be used to on the API layer)
As far as validation. You could just put attributes on the properties of the Request like [Required] and they would automatically be validated before your Get method is called. Of course if the types don't match, the framework would send the appropriate error.