Ответ 1
Web API имеет концепцию Per-Controller, предназначенную для сценариев, подобных вашим. Конфигурация на контроллере позволяет иметь конфигурацию на основе каждого контроллера.
public class MyConfigAttribute : Attribute, IControllerConfiguration
{
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
// controllerSettings.Formatters is a cloned list of formatters that are present on the GlobalConfiguration
// Note that the formatters are not cloned themselves
controllerSettings.Formatters.Remove(controllerSettings.Formatters.JsonFormatter);
//Add your Json formatter with the datetime settings that you need here
controllerSettings.Formatters.Insert(0, **your json formatter with datetime settings**);
}
}
[MyConfig]
public class ValuesController : ApiController
{
public string Get(int id)
{
return "value";
}
}
В приведенном выше примере ValuesController будет использовать форматировщик Json с настройками даты, но остальные контроллеры в вашем случае будут использовать тот, который установлен на GlobalConfiguration.