Forked from ShawInnes/AutofacFluentValidationModule.cs
Created
October 15, 2018 23:47
-
-
Save stephenpatten/29e12be339f6a56861d20a95bdb6b9f5 to your computer and use it in GitHub Desktop.
Autofac Fluent Validation Module (MVC 5)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Autofac; | |
using FluentValidation; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Mvc; | |
namespace WebSite | |
{ | |
public class AutofacFluentValidationModule : Module | |
{ | |
protected override void Load(ContainerBuilder builder) | |
{ | |
AssemblyScanner findValidatorsInAssembly = AssemblyScanner.FindValidatorsInAssembly(typeof(Grunch.Validation.GroupOrderValidator).Assembly); | |
foreach (AssemblyScanner.AssemblyScanResult item in findValidatorsInAssembly) | |
{ | |
builder | |
.RegisterType(item.ValidatorType) | |
.Keyed<IValidator>(item.InterfaceType) | |
.As<IValidator>(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment