Archive for category NHibernate.Validator
NHibernate Validator 1.2 Beta3 released
Posted by Dario in NHibernate, NHibernate.Contrib, NHibernate.Validator on October 26th, 2009
NHibernate Validator 1.2 Beta2 released
Posted by Dario in NHibernate, NHibernate.Validator on October 10th, 2009

Download NHibernate Validator 1.2 beta2 with sources, binaries and example here here
For use it with NHibernate 2.1 GA.
Enjoy it !
NHibernate Validator Quickstart
Posted by Dario in Asp.Net MVC, NHibernate.Validator, Quickstart, Web on May 18th, 2009

The NHibernate Validator Team had prepared examples to you be able to use this validation framework in a easy way. With four examples we are covering the following topics:
1) Winforms
In this example you will how you can easily integrate NHibernate Validator and some helper clases with System.Windows.Forms.
2) NHibernate Integration
Trying to integrate NHibernate Validator with NHibernate? Not a problem. In this example you will how really get these 2 great frameworks working together. NHibernate Validator let you intercept Saves and Updates from NHibernate validating your entities before these changes take place. Note you have to create a database based on the configured connection string.
3) Asp.Net MVC
Asp.Net MVC has a cool way to add validation errors from model and display them all into the View. This example cover the easy integration between these frameworks. Note, you need Asp.Net MVC installed into your machine.Download Asp.net MVC
4) Entity Validator
Sometimes you need to validate a property which depends of another(s) property(ies). The most common example is when you have to validate a range of dates. This example cover this funcionality and show to us how to configurate it using attributes, xml and fluent.
Download it here
NHibernate Validator and Asp.Net MVC
Posted by Dario in Asp.Net MVC, NHibernate.Validator on April 2nd, 2009
Download the example here.
Asp.Net MVC has a cool way to add validation errors from the model and display them all into the View. It?s actually using the ModelState. As you may know NHibernate Validator (NHV) is a framework to validate entities, so what about if we let the validation to the framework that can manage it? So the integration of NHV to Asp.Net MVC is easy. I created a new Asp.Net MVC project and added some files to my solution to make they look like this: 
First I added the libraries needed to NHV (this libraries we need in case to use NHibernate too, otherwise you don?t need Linfu stuff to get proxies working). The libraries are:

Once the libraries are referenced, NHV need to be initialized, actually in this example that initialization will consist in a Validator Engine provider, capable to be accessed from everywhere into our web-application. A good point do this, is in the Global.asax. The next method InitializeValidator it?s called from the Application_Start.

Then I created a new View Manage.aspx, actually the view is a copy, with modifications, of Register.aspx View. Such View should looks like this one. As you may see, seems like there are some messages of validation, means, a validation that didn?t pass. Now let?s see the code to explore the minimal code to introduce NHibernate Validator as a Framework to Validate our MVC application.
First of all, our entity Customer, which reflex the view with a Name and a Email properties, should looks like this with the NHV attributes. Remember that NHV can be configured using Attributes (default), Xml or Fluent-Interfaces, and accept mix of configurations too.

Second, we need the integration point between NHibernate Validator and Asp.Net MVC, and that point consist just in a little piece of code that make the validation and modifies the current state of the model. We need just a few lines:

The picture shows an extension method which first of all, get a new ValidatorEngine instance, which is a singleton in whole web application. Actually, to use a ValidatorEngine we need just one instance, because NHV make a lot of useful caching and it configure itself in the way we are using it. Then we validate the entity and get all the InvalidValues of the object. If the entity is in invalid state (break one rule defined), NHV we well generate a InvalidValue array with all errors we should show to the user. Iterate through all the items and we add them all to the ModelState. Once we add one model error, the model is no longer valid.
Once we have our extension, let?s use it.

Validate Method is the extension we made before, and that method is going to modify the ModelState if it?s needed.
And that?s all folks, hope this helps.
NHibernate Validator 1.2 alpha3
Posted by Dario in NHibernate, NHibernate.Validator on March 30th, 2009

Download NHibernate Validator 1.2 alpha3 with sources and binaries here
This release demostrate to be very stable and is an update to use it with NHibernate 2.1alpha2. For those who have NH.Validator 1.2alpha1 this is a mandatory update.
Enjoy it !
New NHibernate and NHibernate Validator releases
Posted by Dario in NHibernate, NHibernate.Contrib, NHibernate.Validator on March 16th, 2009
- NHibernate 2.1 alpha1. See official release. Download.
- NHibernate.Validator 1.2 alpha1. See official release. Download.
NHibernate Validator 1.0 CR1
Posted by Dario in NHibernate, NHibernate.Contrib, NHibernate.Validator on August 25th, 2008
I hope you enjoy this brandnew release of this amazing validator framework. Comes with more stability, more documentation, examples, and the most important point is the full compliance with NHibernate 2.0 GA.
Issues as usual must be reported in our issue-tracker.
Binaries, source and examples: download it here !
Beta1: NHibernate 2.0 y NHibernate Contrib Releases
Posted by Dario in NHibernate, NHibernate.Contrib, NHibernate.Validator on July 1st, 2008
NHibernate Validator Documentation released
Posted by Dario in NHibernate.Validator on June 2nd, 2008
Here is the promised documentation of NHibernate.Validator 1.0.0 Alpha1. You can download it here in different formats: html, pdf and the API via .chm
Download documentation
Integrating NHibernate.Validator with Db4o
Posted by Dario in NHibernate.Validator, db4o on May 22nd, 2008
For who isn’t familiar with NHibernate Validator: it’s a cool framework to validate objects anywhere at our applications. That’s it.
Now, how we can integrate this tool in order to validate the objects before save/update at Db4o? The answer is: very easy. You can download the code at the end of the post.
Remember you can configure NHibernate Validator using .Net Attributes or Xml files. In this case we will se how to do it using the first approach. The class Customer should look like this:

Now how to make the integration using a little helper class ? Like this:

As you see, with a little helper class we can configure the integration with only one line of code, very easy. In this line the method Initialize register before events on the Save/Update at the Db4o Core.
Now, let’s see the validation in action, the below example show the application trying to save an object with an invalid state:

So when the Save/Update is going to happen, first of all, NHibernate Validator check if the entity is into a valid state, if it’s not, an InvalidStateException is thrown, then Db4o wrap it with an EventException, so we have to unwrap the exception to recover the invalid values to display to the user. Would be nice that Db4o don’t wrap the exceptions, but this topic was discussed on this thread.
So, was easy to integrate NHibernate Validator with Db4o. Wasn’t it ?