Forked from ShawInnes/AutofacValidationFactory.cs
Last active
August 29, 2015 14:13
-
-
Save mahizsas/a6214ed3bebe8b36c2be to your computer and use it in GitHub Desktop.
Fluent Validator Factory
This file contains hidden or 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