Created
February 19, 2014 12:43
-
-
Save ShawInnes/9091228 to your computer and use it in GitHub Desktop.
Autofac Validation Factory (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 AutofacValidatorFactory : ValidatorFactoryBase | |
{ | |
private readonly IContainer container; | |
public AutofacValidatorFactory(IContainer container) | |
{ | |
this.container = container; | |
} | |
public override IValidator CreateInstance(Type validatorType) | |
{ | |
IValidator validator = container.ResolveOptionalKeyed<IValidator>(validatorType); | |
return validator; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment