Dependency-Injected Validation in Web API

后端 未结 6 1004
遥遥无期
遥遥无期 2021-02-04 09:05

In MVC, I can create a Model Validator which can take Dependencies. I normally use FluentValidation for this. This allows me to, for example, check on account registration tha

6条回答
  •  半阙折子戏
    2021-02-04 09:49

    This certainly isn't recommended as the class is internal, but you can remove the IModelValidatorCache services in your WebApi config.

    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.Services.Clear(Type.GetType("System.Web.Http.Validation.IModelValidatorCache, System.Web.Http"));
        }
    }
    

提交回复
热议问题