/// <summary> /// Add the <see cref="IModelStateValidator" /> to the dependencies and configure some options. /// </summary> /// <param name="services">The current service collection to be builded.</param> /// <param name="configure">The ModelStateValidateOptions to be configured.</param> /// <returns>The current service collection to be builded.</returns> public static IServiceCollection AddModelStateValidation(this IServiceCollection services, Action <ModelStateValidateOptions> configure) { if (configure != null) { var options = new ModelStateValidateOptions(); configure(options); services.Configure <MvcOptions>(options.ConfigureMvc); } return(services.AddModelStateValidation()); }
private static MvcOptions ApplyOptions(ModelStateValidateOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } var mvcOptions = new MvcOptions(); options.ConfigureMvc(mvcOptions); return(mvcOptions); }
public DefaultModelStateValidator(IObjectModelValidator validator, ModelStateValidateOptions options, IServiceProvider provider) : this(validator, ApplyOptions(options), provider) { }
public DefaultModelStateValidator(IObjectModelValidator validator, ModelStateValidateOptions options) : this(validator, ApplyOptions(options), null) { }