Skip to content

Instantly share code, notes, and snippets.

@jimmason
Created September 28, 2015 10:47
Show Gist options
  • Save jimmason/4ce23c5108542ae1b7ea to your computer and use it in GitHub Desktop.
Save jimmason/4ce23c5108542ae1b7ea to your computer and use it in GitHub Desktop.
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<>));
}
}
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