Files
Umbraco-CMS/src/Umbraco.Web/WebApi/PrefixlessBodyModelValidatorAttribute.cs
2017-07-20 11:21:28 +02:00

21 lines
866 B
C#

using System;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Validation;
namespace Umbraco.Web.WebApi
{
/// <summary>
/// Applying this attribute to any webapi controller will ensure that the <see cref="IBodyModelValidator"/> is of type <see cref="PrefixlessBodyModelValidator"/>
/// </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
controllerSettings.Services.Replace(typeof(IBodyModelValidator),
new PrefixlessBodyModelValidator(controllerSettings.Services.GetBodyModelValidator()));
}
}
}