Validation of ASP.NET controls - Use LLBLGen validators or ASP.NET validators

Posts   
 
    
Posts: 254
Joined: 16-Nov-2006
# Posted on: 01-Mar-2007 10:15:06   

Guys,

I'd like to add validation support to ASP.NET forms. There seem two approaches

a) Use LLBLGen validator classes and then call the validation logic from the server side ASP.NET page when the entity is saved. b) Use ASP.NET validators to perform the validation.

a) Seems preferable because the validation is present at the business logic layer and therefore can ensure that any clients e.g. user interface / other business objects use the same consistent validation and avoid it being duplicated in many places.

If this is the best approach how would you recommend using the LLBLGen validator interfaces when managing the entities in ASP.NET e.g. when creating / updating the entities in the FormView.

Wouldn't it be useful to add another ASP.NET validator type control perhaps which could use the validator code in the LLBLGen entity and adapt this to the interface required for ASP.NET validators?

Cheers

Matt

Btw on another note if a) would be preferable why doesn't the HnD forum source code provide any validator classes?

Posts: 254
Joined: 16-Nov-2006
# Posted on: 01-Mar-2007 11:34:53   

Very related to this I just reviewed the release documentation for a CTP of enterprise library 3.0 which contains a "Validation Application Block". This has the main objectives of

This release of Enterprise Library includes a new Validation Application Block. The goal of this application block is to provide:

· A common approach to defining validation rules for your business objects that allows them to be reused across different layers of your application.

· A set of common validation rule types, and the ability for developers to easily define their own rule types.

· Technology adapters that make it easy to integrate the Validation Application Block with different .NET technologies such as ASP.NET, Windows Forms and Windows Communication Foundation (WCF).

Did anyone have any thoughts on this and how this could be used with LLBLGen / ASP.NET validators too?

Posts: 254
Joined: 16-Nov-2006
# Posted on: 01-Mar-2007 13:31:24   

Reviewing the validation block in more detail perhaps the LLBLGen authors could create support for this so the LLBLGen validator entities can be used in conjunction with the block.

From http://davidhayden.com/blog/dave/archive/2007/01/24/BusinessObjectValidationEnterpriseLibrary.aspx

You can write code such as

[HasSelfValidation]
public class Customer
{
    private string _name;
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
    
    [SelfValidation]
    public void Validate(ValidationResults results)
    {
        if (string.IsNullOrEmpty(_name))
        {
            results.AddResult(
                new ValidationResult(
                    "Name cannot be null.",
                    this,
                    "Name",
                    null,
                    null
                )
            );
        }
    }
}

So perhaps we could leverage the block to retrieve the validation from the validator classes in a similar way. I need to look into this in more detail.

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 01-Mar-2007 14:11:52   

this issue was presented in the v2.1 forums: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=9039

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 01-Mar-2007 14:50:31   

these kind of attributes are pretty much useless: SelfValidation etc. is already build in, you don't have to mark a class with that attribute, entities already do validation.

Furthermore, they tightly couple rule with the target of the rule. What you actually want is define a validator and define WITH that validator on which entities they're applied. This is much more maintainable, as you focus on the rules and then define where the validation takes place.

Validation rules specified in strings in attributes is to me a couple of steps back, because these strings are more or less used by UI controls, but that's not useful: a class should be validatable without a UI, so code has to either be plugged into the class or written inside the class to make that work.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 254
Joined: 16-Nov-2006
# Posted on: 01-Mar-2007 15:16:56