views:

79

answers:

1

Currently I've got a set of EntLib validation rules defined in my classes. The rules will later change based on the client.

What I'd like to do is retain my classes, and simply call the different rule sets defined somewhere for the specific client.

The functionality of this is similar to storing internationalization values in a .resx file, where content changes based on localization parameters, but in this case, the pre-defined rules would change based on the client.

Thank you.

A: 

For those who wonder, given the following ruleset for a TerminalId parameter:

<ValidatorComposition(CompositionType.And)> _
<NotNullValidator(MessageTemplate:="Terminal id is required.", Ruleset:="Default")> _
<StringLengthValidator(1, 19, MessageTemplate:="Terminal id must be between 1 and 19 digits in length.", Ruleset:="Default")> _
Public Property TerminalId() As String
    Get
        Return _TerminalId
    End Get
    Set(ByVal value As String)
        _TerminalId = value
    End Set
End Property

Simply adding an additional rule set identifier would do the trick.

<StringLengthValidator(1, 19, MessageTemplate:="Terminal id must be between 1 and 19 digits in length.", Ruleset:="Client1.Default")>
<StringLengthValidator(3, 10, MessageTemplate:="Terminal id must be between 3 and 10 digits in length.", Ruleset:="Client2.Default")>
<StringLengthValidator(5, 25, MessageTemplate:="Terminal id must be between 5 and 25 digits in length.", Ruleset:="Client3.Default")>

... then simply calling the appropriate validation rule set that matches the logged-in client.

Ah EntLib.

ElHaix