2015-10-08 17:13:38 +02:00
using System ;
using System.Web.Http ;
using System.Web.Http.Controllers ;
using System.Web.Http.Validation ;
namespace Umbraco.Web.WebApi
{
/// <summary>
2017-05-12 14:49:44 +02:00
/// Applying this attribute to any webapi controller will ensure that the <see cref="IBodyModelValidator"/> is of type <see cref="PrefixlessBodyModelValidator"/>
2015-10-08 17:13:38 +02:00
/// </summary>
internal class PrefixlessBodyModelValidatorAttribute : Attribute , IControllerConfiguration
{
public virtual void Initialize ( HttpControllerSettings controllerSettings , HttpControllerDescriptor controllerDescriptor )
{
//replace the normal validator with our custom one for this controller
2017-07-20 11:21:28 +02:00
controllerSettings . Services . Replace ( typeof ( IBodyModelValidator ) ,
new PrefixlessBodyModelValidator ( controllerSettings . Services . GetBodyModelValidator ( ) ) ) ;
2015-10-08 17:13:38 +02:00
}
}
2017-07-20 11:21:28 +02:00
}