Skip to content

Instantly share code, notes, and snippets.

@brendanjerwin
Created March 12, 2009 01:14
Show Gist options
  • Save brendanjerwin/77853 to your computer and use it in GitHub Desktop.
Save brendanjerwin/77853 to your computer and use it in GitHub Desktop.
Initializing both Fluent NHibernate and NHibernate Validator
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