public static void AddPropertyValidators(this FluentValidationModelValidatorProvider provider)
 {
     provider.Add(typeof(GreaterThanValidator),
                  (metadata, context, rule, validator) => new GreaterThanPropertyValidator(metadata, context, rule, validator));
     provider.Add(typeof(GreaterThanOrEqualValidator),
                  (metadata, context, rule, validator) => new GreaterThanOrEqualPropertyValidator(metadata, context, rule, validator));
     provider.Add(typeof(LessThanValidator),
                  (metadata, context, rule, validator) => new LessThanPropertyValidator(metadata, context, rule, validator));
     provider.Add(typeof(LessThanOrEqualValidator),
                  (metadata, context, rule, validator) => new LessThanPropertyValidator(metadata, context, rule, validator));
 }
Exemplo n.º 2
0
        protected void Application_Start()
        {
            AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;

            EngineContext.Initialize(false);
            //注入相关接口
            var dependencyResolver = new HrDependencyResolver();

            DependencyResolver.SetResolver(dependencyResolver);


            AreaRegistration.RegisterAllAreas();
            //验证信息注册

            FluentValidationModelValidationFactory validationFactory = (metadata, context, rule, validator) => new RemoteFluentValidationPropertyValidator(metadata, context, rule, validator);
            var validationProvider = new FluentValidationModelValidatorProvider(new LuckyValidatorFactory());

            validationProvider.Add(typeof(RemoteValidator), validationFactory);
            ModelValidatorProviders.Providers.Add(validationProvider);
            DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new ThemeViewEngine());
        }
    public static void Register(IContainer container)
    {
        ModelValidatorProviders.Providers.Clear();
        DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
        var fvmvp = new FluentValidationModelValidatorProvider(new FluentValidatorFactory(container))
        {
            AddImplicitRequiredValidator = false,
        };

        FluentValidationModelValidationFactory validationFactory = (metadata, context, rule, validator) => new RemoteFluentValidationPropertyValidator(metadata, context, rule, validator);

        FluentValidationModelValidatorProvider.Configure(x => x.Add(typeof(RemoteValidator), validationFactory));
        fvmvp.Add(typeof(RemoteValidator), validationFactory);
        ModelValidatorProviders.Providers.Add(fvmvp);
    }