José, thanks for the help. This solved the problem!

On Jan 3, 2:32 pm, José F. Romaniello <[email protected]> wrote:
> I think you are missing the SharedEngineProvider thing, specially this part:
>
>             Environment.SharedEngineProvider = XYZ;
>
> something like:
>
> Environment.SharedEngineProvider = MyEngineProvider(validatorEngine);
>
> this way you tell NHibernate what engine should use.
>
> http://fabiomaulo.blogspot.com/2009/02/diving-in-nhibernatevalidator....
>
> I wrote a post in nhforge sometime 
> ago:http://nhforge.org/wikis/howtonh/setup-nhv-fluently-with-your-ioc-con...
>
> 2010/1/2 Stephan Zahariev <[email protected]>
>
> > Hello
>
> > I'm using NHibernate 2.1.2.4000 and NHibernate.Validator 1.2.0.3001. I
> > have read this post
> >http://fabiomaulo.blogspot.com/2009/02/nhibernatevalidator-fluent-int...
> > but unfortunately the validation is not working as expected. Entities
> > with invalid values are still persisted without exception.
>
> > My configuration code looks like this:
>
> >        private static readonly NHibernate.Cfg.Configuration
> > Configuration;
> >        private static readonly ISessionFactory SessionFactory;
>
> >        static NHibernateSessionFactory()
> >        {
> >            Configuration = Fluently.Configure()
> >               .Database(MsSqlConfiguration.MsSql2008
> >                             .ConnectionString(c =>
> > c.FromConnectionStringWithKey
> > ("NavigatorConnectionString")).UseReflectionOptimizer())
>
> >                // Mappings
> >                .Mappings(m => m.FluentMappings.AddFromAssembly
> > (Assembly.Load("Navigator.Data")).ExportTo(@"C:\Temp"))
>
> >                // Properties
> >                .ExposeConfiguration(x => x.Properties.Add
> > (Environment.UseSecondLevelCache, "false"))
> >                .ExposeConfiguration(x => x.Properties.Add
> > (Environment.GenerateStatistics, "true"))
> >                .ExposeConfiguration(x => x.Properties.Add
> > (Environment.ShowSql, "true"))
> >                .BuildConfiguration();
>
> >            //Init NHibernate Validator
> >            var configure = new
> > NHibernate.Validator.Cfg.Loquacious.FluentConfiguration();
> >            configure
> >                .SetDefaultValidatorMode(ValidatorMode.UseExternal)
> >                .Register(Assembly.Load("Navigator.Validator")
> >                    .ValidationDefinitions())
> >                .IntegrateWithNHibernate
> >                    .RegisteringListeners();
>
> >            var validatorEngine = new ValidatorEngine();
> >            validatorEngine.Configure(configure);
>
> >            ValidatorInitializer.Initialize(Configuration,
> > validatorEngine);
>
> >            SessionFactory = Configuration.BuildSessionFactory();
> >        }
>
> > The Rules are defined like:
>
> >    public class LapRules : ValidationDef<Lap>
> >    {
> >       public LapRules()
> >       {
> >           Define(x => x.Notes)
> >               .LengthBetween(5, 50)
> >               .WithMessage(RuleMessenger.LengthBetween("Notes", 5,
> > 50));
> >       }
> >    }
>
> > After saving the Lap entity to the database, with Notes property = ab,
> > no exception is raised. I have used the NHibernate.Validator v 1.0
> > with attributes above the entity properties and exception was raised
> > during the persistance of invalid entity.
>
> > I have debugged the application and the Assembly.Load
> > ("Navigator.Validator").ValidationDefinitions() returns the correct
> > number of *Rules classes. As well the line
> > ValidatorInitializer.Initialize(Configuration, validatorEngine);
> > correctly registers
> > NHibernate.Validator.Event.ValidatePreInsertEventListener to the
> > EventListeners.PreInsertEventListener collection.
>
> > So the question is what I'm doing wrong?
>
> > Best regards
> > Stephan
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<nhusers%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.
>
>

--

You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.


Reply via email to