i am integrating nhibernate validator into my application and and everything is fine with attributes but as soon as I create *.nhv.xml files and move my validation rules there (as embedde开发者_运维知识库d resource)
ValidatorEngine.Validate(entity)
returns wrong (actually nothing and my InvalidValue[]
collection is empty
I appropriate any comment/advise
The problem was because of configuration part of the nhibernate validator
first the
NHibernateSharedEngineProvider
should get assigned to
NHibernate.Validator.Cfg.Environment.SharedEngineProvider
then
we have to call the current engine's Configure
not a new instance
of ValidatorEngine
so the full configuration section may look like this:
var provider = new NHibernateSharedEngineProvider();
NHibernate.Validator.Cfg.Environment.SharedEngineProvider = provider;
var nhvConfiguration = new FluentConfiguration();
nhvConfiguration
.SetDefaultValidatorMode(ValidatorMode.UseExternal)
.Register(Assembly.Load("assembley name")
.ValidationDefinitions())
.IntegrateWithNHibernate
.ApplyingDDLConstraints()
.And
.RegisteringListeners();
var validatorEngine = NHibernate.Validator.Cfg.Environment.SharedEngineProvider.GetEngine();
validatorEngine.Configure(nhvConfiguration);
精彩评论