I have a module that is meant to keep all the code that is specific to contact related data in one place.
The contact data is stored in a contact table. You can think of it as the Assignment module in PTracker.Library.
What I also want it to contain, is the definition of contact specific validation rules, specifically the rules concerning the db-column definition (-> StringMaxLength...). So in case the table definition changes, I only have to look at one place.
Here is how I am thinking it could work:
First the module:
Friend Module Contacts
Public Interface IContacts
ReadOnly Property FirstNameProperty() As Csla.Core.IPropertyInfo
...
End Interface
#Region " Validation Rules "
Public Sub RegisterBusinessRules(Of T As {Csla.BusinessBase(Of T),
IContacts}) _
(ByVal rules As Csla.Validation.ValidationRules, _
ByVal bo As IContacts)
'
' strFirstNameContact
'
rules.AddRule(Of T)(AddressOf
Csla.Validation.CommonRules.StringMaxLength, New
Csla.Validation.CommonRules.MaxLengthRuleArgs(bo.FirstNameProperty, 30))
End Sub
#EndRegion
End Module
Now my business object that has contact data:
Public Class Customer
Inherits BusinessBase(Of Customer)
Implements IContacts
Private Shared FirstNameProperty As PropertyInfo(Of String) =
RegisterProperty(New PropertyInfo(Of String)("FirstName", "First Name"))
...
Friend Property _FirstNameProperty As Csla.Core.IPropertyInfo Implements IContacts.FirstNameProperty
Return FirstNameProperty
End Property
#Region " Validation Rules "
Protected Overrides Sub AddBusinessRules()
Contacts.RegisterBusinessRules(Of Customer)(ValidationRules, Me)
...
End Sub
#End Region
...
End Class
Any problems that I may encounter on my route?
Stefan