Created
March 12, 2009 01:14
-
-
Save brendanjerwin/77853 to your computer and use it in GitHub Desktop.
Initializing both Fluent NHibernate and NHibernate Validator
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
private static ISessionFactory ConfigureNHibernate(IPersistenceConfigurer databaseConfigurer, | |
out ValidatorEngine validatorEngine, | |
NHibernate.Cfg.Configuration cfg) | |
{ | |
ValidatorEngine ve = null; | |
var factory = Fluently.Configure(cfg) | |
.Database(databaseConfigurer) | |
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<PatientMap>()) | |
.ExposeConfiguration(c => | |
{ | |
ve = ConfigureValidator(c); | |
c.SetProperty("adonet.batch_size", "5"); | |
c.SetProperty("generate_statistics", "true"); | |
}) | |
.BuildSessionFactory(); | |
validatorEngine = ve; | |
return factory; | |
} | |
private static ValidatorEngine ConfigureValidator(NHibernate.Cfg.Configuration nhibernateConfiguration) | |
{ | |
NHibernate.Validator.Cfg.Environment.SharedEngineProvider = new SharedValidatorProvider(); | |
var nhvc = new NHVConfiguration(); | |
nhvc.Properties[NHibernate.Validator.Cfg.Environment.ApplyToDDL] = "true"; | |
nhvc.Properties[NHibernate.Validator.Cfg.Environment.AutoregisterListeners] = "true"; | |
nhvc.Properties[NHibernate.Validator.Cfg.Environment.ValidatorMode] = "UseAttribute"; | |
var ve = new ValidatorEngine(); | |
ve.Configure(nhvc); | |
ValidatorInitializer.Initialize(nhibernateConfiguration, ve); | |
return ve; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment