public void Given() { var container = new Container(register => { register.Scan(s => { s.AssemblyContainingType <RulesForRequest>(); s.ConnectImplementationsToTypesClosing(typeof(AbstractValidator <>)); }); }); ValidatorFactory = new StructureMapValidatorFactory(container); }
public static void Init() { var factory = new StructureMapValidatorFactory(); ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider(factory)); DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false; ValidatorOptions.DisplayNameResolver = (type, info, arg3) => { if (info != null) { return(info.Name.TA()); } return(null); }; ValidatorOptions.ResourceProviderType = typeof(TranslateResource); }
public void Configuration(IAppBuilder app) { var container = new Container(c => { c.For <ILogger>().Use <Logger>(); c.Scan(scan => { scan.TheCallingAssembly(); scan.ConnectImplementationsToTypesClosing(typeof(IValidator <>)); }); }); var validatorFactory = new StructureMapValidatorFactory(container); var config = new HttpConfiguration(); config.Formatters.Remove(config.Formatters.XmlFormatter); config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); config.Filters.Add(new InputValidationFilter(validatorFactory)); config.Filters.Add(new ValidateModelStateFilter()); // Bind all commands decorated with IFromUriCommand from the Uri. //config.ParameterBindingRules.Insert(0, // desc => typeof(IFromUriCommand).IsAssignableFrom(desc.ParameterType) // ? new FromUriAttribute().GetBinding(desc) // : null); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); app.UseWebApi(config); }