Created
September 28, 2015 10:47
-
-
Save jimmason/4ce23c5108542ae1b7ea to your computer and use it in GitHub Desktop.
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
public class ValidationRegistry : Registry | |
{ | |
public ValidationRegistry() | |
{ | |
Scan(x => | |
{ | |
x.TheCallingAssembly(); | |
x.With(new ValidatorRegistrationConvention()); | |
}); | |
// Add the empty validator so that you don't have to manually create empty validators for entities | |
// which have no rules | |
For(typeof(IValidator<>)) | |
.LifecycleIs(InstanceScope.Singleton) | |
.Use(typeof(EmptyValidator<>)); | |
} | |
} |
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 System; | |
using MuonLab.Validation; | |
using StructureMap.Configuration.DSL; | |
using StructureMap.Graph; | |
using StructureMap.TypeRules; | |
namespace StopSmokingWeb.Infrastructure.Validation | |
{ | |
public class ValidatorRegistrationConvention : IRegistrationConvention | |
{ | |
public void Process(Type type, Registry registry) | |
{ | |
var validatorTypes = type.FindInterfacesThatClose(typeof(IValidator<>)); | |
foreach (var validatorType in validatorTypes) | |
registry.AddType(validatorType, type); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment