I have a ASP.NET WEB API application that is very "GET" intensive. Most of the methods accept variation of params where method signature varies
For example
[HttpGet]
public async Task<HttpResponseMessage> GetProducts(int year)
{
//...
}
[HttpGet]
public async Task<HttpResponseMessage> GetProducts(int year, string category)
{
//...
}
[HttpGet]
public async Task<HttpResponseMessage> GetProducts(int year, string category, int minPrice)
{
//...
}
[HttpGet]
public async Task<HttpResponseMessage> GetProducts(int year, string category, decimal minPrice, decimal maxPrice)
{
//...
}
I want to use data annotations from System.ComponentModel.DataAnnotations
but I noticed that I must convert all simple url parameters to models? In another words, I have to create input model for every method variation (see example below).
[HttpGet]
public async Task<HttpResponseMessage> GetProducts([FromUri] yearModel)
{
//...
}
public class YearModel
{
[Required]
[Range(1966, 2013)]
public int Year { get; set; }
}
If I want to preserve my method variations and still use data annotations is there a way I could use them without creating all the input models (is there a way to use them "inline" somehow?)?