Skip to content

Instantly share code, notes, and snippets.

@ShawInnes
Created February 19, 2014 12:42
Show Gist options
  • Save ShawInnes/9091220 to your computer and use it in GitHub Desktop.
Save ShawInnes/9091220 to your computer and use it in GitHub Desktop.
Autofac Fluent Validation Module (MVC 5)
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