Files
Umbraco-CMS/src/Umbraco.Web.Common/Mvc/UmbracoMvcConfigureOptions.cs
2022-09-19 11:03:16 +02:00

27 lines
1.1 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Web.Common.Filters;
using Umbraco.Cms.Web.Common.ModelBinders;
using Umbraco.Cms.Web.Common.Validators;
namespace Umbraco.Cms.Web.Common.Mvc;
/// <summary>
/// Options for globally configuring MVC for Umbraco
/// </summary>
/// <remarks>
/// We generally don't want to change the global MVC settings since we want to be unobtrusive as possible but some
/// global mods are needed - so long as they don't interfere with normal user usages of MVC.
/// </remarks>
public class UmbracoMvcConfigureOptions : IConfigureOptions<MvcOptions>
{
/// <inheritdoc />
public void Configure(MvcOptions options)
{
options.ModelBinderProviders.Insert(0, new ContentModelBinderProvider());
options.ModelValidatorProviders.Insert(0, new BypassRenderingModelValidatorProvider());
options.ModelMetadataDetailsProviders.Add(new BypassRenderingModelValidationMetadataProvider());
options.Filters.Insert(0, new EnsurePartialViewMacroViewContextFilterAttribute());
}
}