Files
Umbraco-CMS/src/Umbraco.Web/WebApi/PrefixlessBodyModelValidatorAttribute.cs

21 lines
866 B
C#
Raw Normal View History

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"/>
/// </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()));
}
}
2017-07-20 11:21:28 +02:00
}