public static void RegisterValidatorsFromAssemblies(this FluentValidationMvcConfiguration builder, Func <Assembly, bool> canScan = null) { if (null == canScan) { canScan = (file) => true; } foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { try { if (!canScan(assembly)) { continue; } builder.RegisterValidatorsFromAssembly(assembly); } catch (BadImageFormatException) { } catch (FileLoadException) { } catch (Exception) { } } }
protected override void ConfigureFluentValidation( FluentValidationMvcConfiguration configuration) { base.ConfigureFluentValidation(configuration); configuration.RegisterValidatorsFromAssembly(Assembly.GetExecutingAssembly()); }
static void RegisterValidators(FluentValidationMvcConfiguration conf) { Console.WriteLine("Register"); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.IsDynamic && a.DefinedTypes.Any(t => typeof(IRequestValidator).GetTypeInfo().IsAssignableFrom(t) && !t.IsAbstract))) { conf.RegisterValidatorsFromAssembly(assembly); } }
private static void SetFluentValidationConfiguration(FluentValidationMvcConfiguration options) { options.RegisterValidatorsFromAssembly(Assembly.GetExecutingAssembly()); options.RunDefaultMvcValidationAfterFluentValidationExecutes = false; options.AutomaticValidationEnabled = false; // so we can use our own exception handler }